0
votes

I have a Tab Bar Controller that has a navigationcontroller with a view controller attached. For some unknown reason the navigation bar of the view controller does not look like it always does. Instead the view controller's navigation bar is added below the navigation controller's.

When I look at the view controllers embedded in the first navigation controller before the Tab Bar Controller is shown, it works as expected.

This it what it should look like

enter image description here

And this

enter image description here

Now when I segue to the Tab Bar Controller which has a new navigation controller with a view controller embedded it looks like this:

enter image description here

I don't want an additional navigation bar below the one provided by the navigation controller. I want the title and the item of the view controller merged with the navigation controller. So the final result should display a row with the back button, the title and the bar button item(Search Image)

What am I missing?

I've also tried adding the navigation items programmatically but nothing seemed to work.

Project on github

My Code

    //
//  SideViewController.swift
//  Sample
//
//  Created by  on 08.02.20.
//  Copyright © 2020 . All rights reserved.
//

import UIKit

class SideViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Search"

    }
    @objc func action(){

    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
1

1 Answers

0
votes

There is two ways that I found you can resolve this either by presenting tab bar controller modally or hiding navigation bar of a tab bar controller when view loads.

First solution can be achieved like this:

  1. Open Main.storyboard.
  2. Select last segue in this storyboard(one that navigates to Side storyboard).
  3. Make sure that you have Attribute Inspector selected. Now change Kind attribute to Present Modally and Presentation attribute to Full Screen. enter image description here

And second solution can be achieved like this:

  1. Create new file by selecting File > New > File > Cocoa Touch Class and press Next.
  2. Change Subclass of: to UITabBarController and name your class to whatever make sense to you.
  3. Then inside of viewDidLoad() paste this navigationController?.navigationBar.isHidden = true in order to hide current navigation bar.
  4. Assign your class to TabViewController in the Side storyboard by selecting TabViewController and changing Class attribute to your class name in Identity Inspector. It should autocomplete when you entering your class name. Press Enter to make sure that you confirm the changes.

Remember to make just one of this two solutions. Which one would it be is up to your needs.