我有一个带有很多 viewControllers
的 UINavigationController
,我想在右上角添加一个 UIBarButtonItem
。我这样做了,但我必须对每个 View Controller 单独执行此操作。添加一次并在整个应用程序中保留它的最佳模式是什么?
最佳答案
是的,您可以像在 appDelegate 中一样创建一个全局函数,并在该函数上传递一些参数。比如传递你的 navigationController、target、selector。
这是示例代码片段。
- (UIBarbuttonItem *) rightBarButtonGlobal:(UINavigationItem*)navigationItem target:(id)target {
//you can also pass nsstring for title and selector for you desired selector.
//But as per your question I assume you want a application logo like button in navigation bar. If that is the case just pass navigationItem as parameter.Create your logo button and assign to navigationItem.
//Allocate button here
navigationItem.rightBarButtonItem = button;
[button release];
}
关于objective-c - 像 Twitter 的 Compose Button 一样的全局/持久 UIBarButtonItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554733/