如何在Swift3

时间:2016-10-31 17:57:42

标签: 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)
}

我现在需要的是调用超级方法:super.viewWillAppear(animated)super.viewWillDisappear(animated),但我不知道在何处或如何提出任何建议?

2 个答案:

答案 0 :(得分: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)
}

答案 1 :(得分:0)

@Karun Kumar所写的答案是正确的,但在super之后有一个空格。 viewwill出现和viewwilldisapper。

正确的代码是

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)
}