1

在我的應用程序,它有很多的ViewController類以及tableviewcontroller班我想告訴navigationcontroller具有如何在iphone中使用靜態方法使用self.navigationitem屬性?

//creation of toolbar 
UIToolbar *tool = [UIToolbar new]; 
tool.frame = CGRectMake(0, 0, 320, 42); 
//create setting button 
UIButton *bttn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 30)]; 
[bttn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchDown]; 
UIBarButtonItem *back=[[UIBarButtonItem alloc]initWithCustomView:bttn]; 

//Space 
UIBarButtonItem *spbtn = [[UIBarButtonItem alloc] init]; 

spbtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: 
     UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

//Show Logo 
UIButton *bttn1; 
bttn1= [UIButton buttonWithType:UIButtonTypeCustom]; 
bttn1.frame = CGRectMake(20, 0, 230, 30); 
bttn1.backgroundColor = [UIColor clearColor]; 
[bttn1 addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside]; 
UIImage *imgss =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"pic" ofType:@"png"]]; 
UIImage *strechableImage1 = [imgss stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
[bttn1 setBackgroundImage:strechableImage1 forState:UIControlStateNormal]; 
UIBarButtonItem *logo; 
logo=[[UIBarButtonItem alloc]initWithCustomView:bttn1]; 

//assign toolbar into navigation bar 
NSArray *items = [NSArray arrayWithObjects:back,logo,spbtn,nil]; 
[tool setItems:items animated:YES]; 
tool.barStyle =UIBarStyleBlackOpaque; 
tool.backgroundColor = [UIColor clearColor]; 
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tool]; 

我想在每堂課的上方顯示navigatedtoolbar所有類。爲此我必須在每個類中編寫這段代碼,但是我想刪除重複,我定義了一個具有靜態方法的類,我嘗試在此方法中執行該操作,但生成錯誤,我可以做些什麼來簡要提供一些指導。

回答

0

我找到解決其非常簡單通過繼承的概念 創建一個基類,顯示navigatedtoolbar然後我用基類文件的超

0

是的,你可以使用

是否可以使用self.navigationbar。

0

的UINavigationController有一個工具欄了。如果要啓用該功能,則只需從viewControllers提供應位於工具欄上的按鈕即可。 Apple的Mail應用程序使用這個概念。這樣做的好處是,在導航堆棧動畫過程中,您看不到工具欄離開屏幕,這使得它看起來好像坐在工具欄上的所有按鈕和按鈕之上,並根據當前屏幕上的UIViewController進行更改。

相關問題