Reputation: 3137
I have this structure:
When I want to add a ´UINavigationItem´ from the storyboard the navigation bar is "disabled", so I tried to add the right button programatically:
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(showPickerView:)];
self.navigationItem.rightBarButtonItem = button;
But nothing happens. I renamed the navigation bar title from storyboard, but when I run the app the title is not set. I really don't know what is the source of the problem. There is just the back button that is appearing. Thank you for your help.
Upvotes: 1
Views: 5395
Reputation: 19222
As other answers have pointed out, the hierarchy of your UINavigationViewController
is incorrect. The UITabBarViewController
will always be the parent of your UINavigationViewControllers
.
For each UIViewController that is a "Tab", you need your UINavigationViewController
to be "in front" of each "tab" UIViewConrolller that will have segues.
So you do not need a UINavigationViewController for every "tab" UIViewController
, as someone else pointed out on this thread, only for "tabs" that will segue to other Views that you want to track navigation with a UINavigationViewController
The hierarchy can be seen in @App Dev Guy's answer here
In Swift 2, Xcode 7 has a very handy feature for adding a UINavigationController:
UITabBarNavigationController
"Navigation Controller"
Upvotes: 1
Reputation: 119031
Each item in the tab bar controller should have a navigation controller as the root controller (well, you don't need all of them to have a nav controller if you don't need them). What you currently have is a tab bar controller in the navigation controller (unless it's modal) so the view controllers contained in the tab bar controller can't see out to the navigation controller.
Upvotes: 2
Reputation:
Try it like this. It's a little different than how you are doing it and it works for me:
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithTitle:@"title"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(showPickerView:)];
self.navigationItem.rightBarButtonItem = button;
If you want to do this in the Storyboard, you don't drag the "Navigation Item", but the "Bar Button Item" instead.
Upvotes: 0
Reputation: 1148
I tried to reproduce your problem.
Done. See if you can do the same.
Upvotes: 0