我的应用程序结构:
firstView:UIViewController
和UINavigationController
- 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"
没有任何变化。我仅看到按钮“后退” 。
答案 0 :(得分:1)
在 viewDidLoad()
方法
self.title = "Your Title"