hi im developing an ios aplication and the ui was desigbed using the storyboard (first time using it) so i have the folowing:
- entry point: navigation Controller
- rootView view controller (push to many other view some of one are UITableView)
- and then i programatically push (in some controllers) a view loaded from a nib (no problem on this)
each controller has a defined title.
what i want to do is put a rigth button on the nav bar of all view controller so i can push (programatically) to another controller (wish is in a nib, but i coul move it to the SB whit no problem)
i have tried:
- using a custom class and an nib file but i get the same uncustumised nav bar
- overwriting initWithCoder so i can redirect it to de nib file but get an infinite loop (StakOverflow, yay!)
-
using a second class to avoid the infinite loop but get an exception:
Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘This coder requires that replaced objects be returned from initWithCoder:
-
add the button manually in the init method of the navbar class, no efect
- replace the navigation bar in the navigation controller initWithCoder, no efect
- same but in the viewDidLoad method of the navigation controller, no efect
- same but in the rootView Controller, no efect
the code i was using was this (and a few variations):
UIBarButtonItem *BTN = [[UIBarButtonItem alloc]
initWithImage:[[UIImage alloc] initWithContentsOfFile:@"img.png"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(pushView)];
[[self navigationItem] setRightBarButtonItem:BTN];
is ther any way that i can archive this, or should i do it manually view per view?
–thanks
Yes, you would need to do in each view controller for it’s
navigationItemproperty. But you can make it easier by creating acategoryonUIBarButtonItemclass which will have a method configuring and returning the button you need everywhere.So you only need to invoke that category’s method and no need to write same code everywhere.
Here are some similar posts:
Adding same button to all view controllers in UINavigationController
Adding UIBarButtonItem to all Navigation View Controllers inside a UITabBarController programmatically