Search code examples
iosobjective-cuibuttonuinavigationbaruitabbar

How to use same UINavigationBar for all UIViewControllers


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?


Solution

  • 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.