Mzochi Mzochi - 1 month ago 12
Swift Question

how to override viewWillDisappear in Swift3

I'm Trying to hide the first navigation bar and show all the others, so I used:

override func viewWillAppear(_ animated: Bool) {
// Hide the navigation bar on the this view controller
self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
// Show the navigation bar on other view controllers
self.navigationController?.setNavigationBarHidden(false, animated: true)
}


what I need now is to call the super methods:
super.viewWillAppear(animated)
and
super.viewWillDisappear(animated)
, but I don't know where or how, any suggestions?

Answer

Your code will look like

override func viewWillAppear(_ animated: Bool) {
    super. viewWillAppear(animated)
    // Hide the navigation bar on the this view controller
    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
    super. viewWillDisappear(animated)
    // Show the navigation bar on other view controllers
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}