Ios 如何在NavigationController之后在选项卡栏连接的ViewController中显示navigationItem.title
对不起,标题很混乱。我的设置非常简单,如下所示:Ios 如何在NavigationController之后在选项卡栏连接的ViewController中显示navigationItem.title,ios,swift,tabbar,navigationbar,Ios,Swift,Tabbar,Navigationbar,对不起,标题很混乱。我的设置非常简单,如下所示: `Navigation Controller -> View Controller1 -> Tab Bar Controller -> View Controller2 -> View Controller3` 有一个显示序列,由ViewController1中的一个按钮触发,该按钮指向Tab
`Navigation Controller -> View Controller1 -> Tab Bar Controller -> View Controller2
-> View Controller3`
有一个显示序列,由ViewController1中的一个按钮触发,该按钮指向TabBarController。对于视图控制器2和3(连接到选项卡栏控制器),我配置了标题并在右上角添加了一个BarButtonItem。这就是全部。当我运行应用程序时,VC2和VC3的标题和按钮不会显示,即使我直接在.swift类中设置标题:
(self.navigationItem.title=“ViewController2的标题”
)
相反,模拟器在VC2和VC3中向我显示了一个标题,其中只有一个“因此,我终于找到了解决我的问题的办法。ViewController1可以在prepareForSegue方法中发送VC2和VC3的标题,如:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let vc = segue.destinationViewController.navigationItem.title = "new title"
}
或者更好的解决方案:ViewController2设置自己的标题
class ViewController2: UIViewController {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.visibleViewController?.navigationItem.title = "new title"
}
}
你能附上你的故事板文件的图片吗?我用截图更新了我的问题。您可以看到我的标题(第1页和第2页)和按钮。在模拟器中,它们不会出现,只是左侧的后退按钮。