0
votes

I have an issue after clicking on the back button.

I have a first view embedded in a NavigationController with an imageView. The navigation bar is customized with this following code:

override func viewDidLoad() {
    super.viewDidLoad()

    // color the navigation bar and text
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 0, green: 0.24, blue: 0.45, alpha: 1)
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

When user taps on the imageView, the following code is executed:

self.performSegueWithIdentifier("view2", sender: self)

It is a show(push) segue.

When user taps on Back button in view2, it returns to first view but the navigation bar has disappeared!

I think it is masked by something because I can see it during debug by clicking on Debug View Hierarchy.

Last point, if I replace the imageView tap action to go to view2 by a simple bar button and perform the segue in storyboard and not in the code, the issue does not appear.

Any idea to fix it?

2
Not sure though can you try this ?? self.navigationController?.hidesBarsOnTap = false ?? My guess may be it's set to true by any reason and when you tap on imageView it might be hiding :) just a guess :)Sandeep Bhandari

2 Answers

1
votes

I just got it!

I realized that in view2, I make the navigation bar translucent with the code:

override func viewDidLoad() {
    super.viewDidLoad()

    // Set the navigation bar translucent
    navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.navigationBar.translucent = true

So to fix the bug, just remove the translucent attribute before disappearing the view:

override func viewWillDisappear(animated: Bool) {
    navigationController?.navigationBar.translucent = false

Hope that helps someone one day :)

0
votes

place this code:

// color the navigation bar and text
self.navigationController?.navigationBar.barTintColor = UIColor(red: 0, green: 0.24, blue: 0.45, alpha: 1)
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

in viewWillAppear