我有一个UINavigationController
,其中有很多viewControllers
,我想在右上角添加UIBarButtonItem
。我这样做了,但我必须对每个视图控制器单独执行此操作。添加一次并将其保留在整个应用程序中的最佳模式是什么?
答案 0 :(得分:0)
是的,您可以像在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];
}