How to use same UINavigationBar for all UIViewControllers

时间:2015-06-25 18:31:08

标签: ios objective-c uibutton uinavigationbar uitabbar

In my app, I have to show same NavigationBar for all UIViewControllers. This NavigationBar has three buttons and these three buttons which will be act as TabBar functionality, that is each tab has its own stack cycle. I have created custom view for NavigationBar with three buttons, but after adding this custom view to HomeViewController, I have to manually add this custom view for all other view controllers. I don't want to do this.

Is there any simple method to achieve this?

2 个答案:

答案 0 :(得分:2)

There are a couple of ideas that come to mind. First of all, you could use view controller containment and actually have 1 controller that implements your custom nav bar, and then swap out the contained controller as necessary. If that's not feasible, you can simply use inheritance and have all your custom controllers inherit from a controller that has the nav bar in place.

答案 1 :(得分:0)

Another option could be to write your own UINavigationController subclass. I'm not certain if you can override the UNavigationItem behavior, but if you can, you can just just do that -- instead of the UINavigationController taking its child's UINavigationItem to update its own UINavigationBar, the UINavigationBar perhaps just stays the same, like you're expecting/hoping.