I have a UINavigationController
with alot of viewControllers
, and I want to add a UIBarButtonItem
to开发者_如何学Python the top-right. I did that, but I have to do this individually to each view controller. What's the best pattern to add it once and have it stay there throughout the app?
Yes you can create a global function like in appDelegate and pass some parameters on that function. Like pass your navigationController,target,selector.
Here is sample code snippet.
- (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];
}
精彩评论