我已经包含了许多ViewControllers
,并且根据要求,所有ViewControllers必须在右侧包含两个相同的自定义BarButton
项(设置,帮助),因此我创建了一个单独的类{{ {1}}并且其中包含两个NSObject
。
在所有ViewControllers中,我导入了这个类并设置了barButtons,如下所示:
UIButtons
其中, NavigationBarButtonItems *nav=[[NavigationBarButtonItems alloc]init];
self.navigationItem.rightBarButtonItems = [nav BarButtonItems];
是包含 NavigationBarButtonItems
方法中两个自定义按钮的类。
一切都很完美。但问题是,我为其中一个barButtons创建了一个viewController,比如-(NSArray *)BarButtonItems;
,当我点击设置barButton作为设置时,我无法弄清楚如何呈现这个 ViewController(设置) barButton几乎包含在所有viewControllers中。
帮帮我。谢谢!
答案 0 :(得分:0)
在自定义类中创建这样的按钮。
-(void)createSettingbutton:(id)FromClass {
//Create Add category Button
UIButton *addSettingButton=[UIButton buttonWithType:UIButtonTypeCustom];
addSettingButton.frame=CGRectMake(0, 0, 30, 30);
[addSettingButton setBackgroundImage:[[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"" ofType:@"png"]] forState:UIControlStateNormal];
**[addSettingButton addTarget:FromClass action:@selector(ButtonAction) forControlEvents:UIControlEventTouchUpInside];**
UIBarButtonItem *_addSettingButton=[[UIBarButtonItem alloc]initWithCustomView:addSettingButton];
[self.navigationItem setRightBarButtonItem:_addSettingButton];
[_addSettingButton release];
_addSettingButton=nil;
}
现在在要添加设置按钮的viewcontroller
中添加以下代码。
[self createSettingbutton:self];//Second self is the parameter which is passed to 'FromClass' Variable.
现在在同一个viewcontroller中添加设置按钮的操作
-(void)ButtonAction
{
[self.view addSubview:mSettingView.view];
//or
[self.navigationController pushViewController:mSettingView animated:YES]
}