1
votes

I have 3 pages

  • Page 1: Menu
  • Page 2: Menu > Navigation Controller > Map listview
  • Page 3: Menu > Navigation Controller > Map

It's possible to switch between page 2 and 3 but when you click "Back" it always goes to page 1 and I did this using a custom back button.

After having used the custom back button once the following problem appears: When I go to page 2 or 3 from the Menu page (Page 1) the navigation title appears and in less than a second it disappears. How is this possible?

These are the functions I am using:

private func hideAndAddNewBackButton(){
    if backToRoot{
        self.navigationItem.hidesBackButton = true
        let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "back:")
        self.navigationItem.leftBarButtonItem = newBackButton;
        self.title = "Locaties"
    }
}

func back(sender: UIBarButtonItem) {
    if let viewController2 = storyboard!.instantiateViewControllerWithIdentifier("ViewController2") as? ViewController2{
        self.navigationController?.pushViewController(viewController2, animated: true);
    }
}

func needBackToRoot(){
    backToRoot = true;
}

And this is in my viewDidLoad():

var backToRoot:Bool = false;

override func viewDidLoad() {
    super.viewDidLoad()
    self.hideAndAddNewBackButton();
}

My switch button:

@IBAction func showLijst(sender: AnyObject) {
    if let viewController3 = storyboard!.instantiateViewControllerWithIdentifier("Lijst") as? KaartListview{
        viewController3.needBackToRoot();
        self.navigationController?.pushViewController(viewController3, animated: true);
    }
}
2

2 Answers

1
votes

In my case problem was creating custom back button and setting in pushed controller self.navigationController?.navigationBar.topItem?.title = "" My solutions is :

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.isNavigationBarHidden = false
          self.navigationController?.navigationBar.topItem?.title = "SomeTitle"

    }
0
votes

I had a similar issue before and I fixed by using:

navigationController?.navigationBarHidden = false

In the viewDidLoad() function

Like this:

override func viewDidLoad() {
    super.viewDidLoad()

    navigationController?.navigationBarHidden = false
}