我遇到了一个问题!我已经挣扎了好几天了!我的问题是我无法更改 TabBar 项目中的导航标题。
首先,如果用户已经登录,我会从 App delegate 推送到 UITabBarViewController。
let currentUser = PFUser.currentUser()
if currentUser != nil {
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let HomeView : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("4")
let navigationController = application.windows[0].rootViewController as! UINavigationController
navigationController.pushViewController(HomeView, animated: false)
} else {
}
然后在第一项 ViewController 中,我使用它来更改 TitleView 图像等。
let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
self.navigationController!.topViewController!.navigationItem.titleView = imageView
在第二项 ViewController 中,我使用它再次更改标题。
self.navigationController!.topViewController!.navigationItem.titleView = nil
self.navigationController!.topViewController!.navigationItem.title = "Second"
但是当我回到第一个项目时,我应该看到我设置的图像,而不是第二个项目 View Controller 的标题
最佳答案
替换
self.navigationController!.topViewController!.title = "Mes contacts"
与
self.navigationController!.topViewController!.navigationItem.title = "Mes contacts"
关于ios - 如何更改 TabBar 项目导航标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35225898/