伙计们,
我有一个 tabBarController,每个选项卡上都有一个 navigationController。
我想设置导航栏的默认右栏按钮,这样我就不必在 3 个不同的 View Controller 上编写相同的代码。
我尝试了 [[UINavigationBar appearance] setRightBarButtonItem:myButton];
但没有成功,是说:
-[_UIAppearance setRightBarButtonItem:]: 无法识别的选择器发送到实例
然后我尝试创建自己的 UINavigationController 子类,这样我就可以像这样设置按钮:
self.navigationItem.rightBarButtonItem = myButton
但还是没有成功,似乎什么都没有发生可能是因为我此时没有 navigationItem。
有人有其他解决方案吗?
最佳答案
如果你继承自UIViewController
,你可以像这样设置右键
UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"foobar.png"] style:UIBarButtonItemStylePlain target:self action:@selector(myAction)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
关于objective-c - 为 UINavigationController 设置默认的 rightBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12168306/