如何在Swift3中覆盖viewWillDisappear

Mzo*_*och 5 swift swift3

我试图隐藏第一个导航栏并显示所有其他导航栏,所以我使用了:

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)
}
Run Code Online (Sandbox Code Playgroud)

我现在需要的是调用父类的方法:super.viewWillAppear(animated)super.viewWillDisappear(animated),但我不知道在哪里或者怎么样,有什么建议?

Kar*_*mar 10

你的代码看起来像

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)
}
Run Code Online (Sandbox Code Playgroud)