Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to share nav bar across multiple views?

I have three view controllers that I want to have the same navigation bar on but I can't figure out a way to "share" the navbar between those three views. Is there a more efficient way to link up the nav controllers with the view controllers so that I don't have three different navigation controllers even though the navigation controllers are exactly the same?

In addition, I have a tab bar controller if that makes a difference.

Picture to clarify:

enter image description here

like image 218
Jacob Platin Avatar asked Aug 22 '15 19:08

Jacob Platin


People also ask

How do I make multiple navigation bars in HTML?

Create A SubnavUse any element to open the subnav/dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the subnav menu and add the subnav links inside it. Wrap a <div> element around the button and the <div> to position the subnav menu correctly with CSS.


1 Answers

As Ch0k0I8 mentioned, UIAppearance is a good way to set a common UI theme throughout the app.

If you are looking for the same functionality between navigation controllers, then you should subclass UINavigationController and implement the common functionality there. Then you can use your custom navigation controller in the storyboard or in code in the 3 places you wish. To put your custom subclass in the storyboard, drag a UINavigationController onto the storyboard like you normally would, then change the class to your custom navigation controller class in the utilities tab. Here is what a custom UINavigationController subclass might look like:

class CustomNavController: UINavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // do whatever custom setup stuff you want here
    }

    // override other methods for different customizations
}
like image 180
keithbhunter Avatar answered Sep 29 '22 01:09

keithbhunter