13

I've tried to hide the navigation controller for a single view controller with no luck, the navigation bar is hidden for the first vc, but it's not displaying for the second vc.

Here's the code I've used in the first vc:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Hide the Navigation Bar
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    // Show the Navigation Bar
    self.navigationController?.setNavigationBarHidden(false, animated: animated)
}

What's changed in swift 4? That code worked in swift 3...

Jano
  • 62,815
  • 21
  • 164
  • 192
Jonathan Solorzano
  • 6,812
  • 20
  • 70
  • 131

1 Answers1

46

Use code:- Swift 5

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    // Hide the Navigation Bar
    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(true)
    // Show the Navigation Bar
    self.navigationController?.setNavigationBarHidden(false, animated: false)
}
Dilip Tiwari
  • 1,441
  • 18
  • 31