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进行更改。

相关问题