Reputation: 2221
In Interface Builder I created a view as part of a Storyboard which used to be only shown in one different context (as the view of a UITabBarController).
Now I want to reuse this view as part of a UINavigationController view however, which generally works fine. The only problem is that in IB, I placed a button to be the leftBarButtonItem. So when I push that same view Controller on the navigation controller's stack it won't automatically place the backBarButtonItem anymore.
Is there a standard approach on how to deal with that situation? Do I have to remove the button myself, depending on whether the viewcontroller is part of a UITabBarController or UINavigationController? I would like to keep the button in IB. So setting leftBarButtonItem to nil on viewDidDisappear for instance only kind of helps. That does show the backBarButtonItem correctly but when the user goes back to that screen, I would have to set the leftBarButtonItem manually again.
Upvotes: 1
Views: 3211
Reputation: 3136
Then try using this:
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
Upvotes: 5