Gugulethu Gugulethu - 6 months ago 26
iOS Question

Re-Showing the Hairline

I have a two

TableViewControllers
with Embedded Navigation Controllers.
ViewController-1
shows the hairline/shadow under the nav bar and
ViewController-2
doesn't show it when I navigate to it. Navigation is done using the Push Segue

To hide the navigation bar in
ViewController-2
I adding the following lines in
ViewWillAppear
the following:

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = false


When I use the back button to go back to ViewController-1 the Hairline disappears there too but I do not want it to. Is there anyway to ensure that the hairline doesn't hide in
ViewController-1
?

I have tried :

self.navigationController?.navigationBar.barStyle = UIBarStyle.Black


and

self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()


but without much success.

Answer

In the viewWillDisappear (or maybe the viewDidDisappear) method of ViewController-2, add code to undo the changes made in viewWillAppear.

self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.translucent = true