UINavigationController如何在子视图中设置标题等

时间:2018-08-23 12:43:58

标签: ios swift uinavigationcontroller uitabbarcontroller

我的应用程序结构:

firstView:UIViewControllerUINavigationController - secondView UITabBarController和几个UIViewControllers

启动应用程序,firstView:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let vc  = ViewController()
    let navContr = UINavigationController(rootViewController: vc)

    self.window? = UIWindow(frame: UIScreen.main.bounds)

    self.window?.rootViewController = navContr
    self.window?.makeKeyAndVisible()
    return true
}

在firtView中,我单击按钮以打开secondView:

let vc = MyTabController()  // my UITabBarController
self.navigationController?.pushViewController(vc, animated: true)

启动secondView:

class MyTabController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let gen = MyViewController()
        let tabGen = UITabBarItem()
        gen.tabBarItem = tabGen
        tabGen.image = UIImage(named: "general")
        tabGen.title = "Все вопросы" 
        viewControllers = [gen]
        ....
    }

在我的secondView中,要设置标题,在每个标签中都设置UISearchControlleer。但是如果我写ViewController

navigationItem.title = "myTitle"没有任何变化。我仅看到按钮“后退”

Here's the screenshot

1 个答案:

答案 0 :(得分:1)

viewDidLoad() 方法

中设置标题
self.title = "Your Title"