我的应用程序设置如下:

NavigationController
|-StartViewController
  |-Start2ViewController
    |-TabBarController
      |-Tab1ViewController
      |-Tab2ViewController

我想在Tab2ViewController中隐藏导航栏,但不想在Tab1ViewController中隐藏导航栏 . 以下是我的Tab2ViewController代码:

import UIKit

class Tab2ViewController: ICPVC {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("View Wwill Appear Reached")
        self.tabBarController!.navigationController!.setNavigationBarHidden(true, animated: false)          
    }
}

这不起作用,导航栏出现在 Tab1ViewController and Tab2ViewController 中,但是,如果我只在“界面”构建器中切换选项卡的位置,以便 Tab2ViewController 是选项卡中的第一个Viewcontroller,那么它可以工作并且导航栏隐藏在 Tab2ViewController 中并且可以在 Tab1ViewController 中看到

想不通为什么?