【发布时间】:2016-07-21 17:10:26
【问题描述】:
我正在使用此代码以编程方式将 UINavigationController 添加到现有 UIViewController:
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let nav1 = UINavigationController()
let mainView = ReminderController(nibName: nil, bundle: nil)
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window?.makeKeyAndVisible()
现在我想给由 UINavigationController 管理的 NavigationBar 添加一个标题,但大多数时候我得到了这个错误:
不能直接在控制器管理的 UINavigationBar 上调用 pushNavigationItem:animated:
我使用的代码:
let item = UINavigationItem(title: "Reminder")
nav1.navigationBar.pushNavigationItem(item, animated: false)
我尝试过的任何其他方法都给了我同样的错误。那么如何给那个 NavController 添加一个标题呢?
导航栏现在看起来像这样:
【问题讨论】:
标签: ios swift uinavigationcontroller uinavigationbar uinavigationitem