Ios 单击工具栏按钮项时显示视图控制器

Ios 单击工具栏按钮项时显示视图控制器,ios,iphone,uiviewcontroller,uibarbuttonitem,Ios,Iphone,Uiviewcontroller,Uibarbuttonitem,我已经包括了许多ViewControllers,根据要求,所有ViewControllers必须在右侧包含两个相同的自定义BarButton项(设置、帮助),因此我创建了一个扩展NSObject的单独类,并在其中包括两个uibutton 在所有ViewControllers中,我导入了此类并设置了如下BarButton: NavigationBarButtonItems *nav=[[NavigationBarButtonItems alloc]init]; self.navig

我已经包括了许多
ViewControllers
,根据要求,所有ViewControllers必须在右侧包含两个相同的自定义
BarButton
项(设置、帮助),因此我创建了一个扩展
NSObject
的单独类,并在其中包括两个
uibutton

在所有ViewControllers中,我导入了此类并设置了如下BarButton:

    NavigationBarButtonItems *nav=[[NavigationBarButtonItems alloc]init];
    self.navigationItem.rightBarButtonItems = [nav BarButtonItems];
其中,
导航BarButtonItems
是在
-(NSArray*)BarButtonItems中包含两个自定义按钮的类方法

一切都很顺利。但问题是,我为其中一个按钮创建了一个viewController,比如说,
“设置”
,我不知道如何在单击设置按钮时显示此视图控制器(设置),因为设置按钮几乎包含在所有viewController中


帮帮我。谢谢

在自定义类中创建如下按钮

-(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]

    }

以模式显示设置视图控制器,在工具栏按钮上单击事件。您还可以在设置视图上提供关闭按钮,以关闭该视图控制器
[self-createSettingbutton:self]->您不需要在要显示barButtons的类中声明
createSettingButton
。那么,如何调用像[self methodname]这样的方法呢?。它不应该像:[customClassObject createSettingButton:self];?是的……对不起。。它应该是这样的:[customClassObject createSettingButton:self];。实际上,我创建了一个uiviewcontroller类别作为我的自定义类,所以我写了:[self-createSettingbutton:self];。