1
votes

computer science student trying to learn Swift here. Sorry for the image links in advance. Apparently I'm not yet allowed to embed images. I'm playing around with an application that uses navigation controllers and a tab bar controller. The initial view, which I'll call root, is embedded into a navigation controller like this. This is because I want to be able to go back to my root view at some point.

Root segues to a tab bar controller that has two tabs, which I'll call 1A and 2A. 1A and 2A both segue to another VC, which I'll call 1B and 2B. I've embedded 1A and 2A in their own navigation controllers like this so that I can navigate between the A's and B's. If I leave it as is, the navigation bars for 1 and 2 will overlap with the root navigation bar like this. So I wanted to change the height of navigation bars 1 and 2 to be just under the root navigation bar like this.

I tried to accomplish this with the following code in the viewDidLoad methods of 1A and 2A but that didn't do anything.

    override func viewDidLoad() {
        super.viewDidLoad()    
        let bounds = self.navigationController!.navigationBar.bounds
        self.navigationController?.navigationBar.frame = CGRect(x: 0, y:   0, width: bounds.width, height: 100)
    }

I've read apple's documentation on Navigation Controllers and bars etc. And I've visited various threads here but I haven't found a solution specific to my problem. Maybe I'm missing something so rudimentary that there is no question for it. Anyways, an example and explanation would be greatly appreciated. Thanks

1
Nooo. You can't do that. And if do it, say, you do it in the most customisable way, users will think that your app has a bug. You can only have one navigation bar per screen!Glenn Posadas
Hide the root navigationController's navigationBar when you push to tabbaController and show when you popToRootkathayatnk
Apple would reject this, take a look at their guidelines: developer.apple.com/design/human-interface-guidelines/ios/bars/…Jurgen
@Glenn eventually, I'm going to replace the root back button with something like a home icon so that it'll be a home button and then below is the back button. Would that still be unacceptable?kelelenceu

1 Answers

0
votes

I found the correct answer here: How to move back to the root view controller in storyboard? I should have been using an unwind segue to navigate back through multiple views