【发布时间】:2016-12-07 00:07:41
【问题描述】:
我使用连接到UINavigationController 的UIPageViewController 来显示两个页面,一个用户表和一个聊天表。
我正在尝试实现以下内容:
Users 和 Chat 两个按钮,点击后会出现相应的视图控制器。我想要导航栏上的这些按钮。
这是我在页面视图控制器类中编写的代码
viewDidLoad()
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc1 = storyBoard.instantiateViewControllerWithIdentifier("users")
let vc2 = storyBoard.instantiateViewControllerWithIdentifier("chat")
vcArray = [vc1, vc2]
self.setViewControllers([vc1], direction: .Forward, animated: true, completion: nil)
let button1 = UIButton(frame: CGRectMake(0, 30, self.view.frame.width/2, 30))
let button2 = UIButton(frame: CGRectMake(self.view.frame.width/2+1, 30, self.view.frame.width/2, 30))
button1.setTitle("Users", forState: .Normal)
button2.setTitle("Chat", forState: .Normal)
self.navigationController?.navigationBar.topItem?.titleView?.addSubview(button1)
self.navigationController?.navigationBar.topItem?.titleView?.addSubview(button2)
很遗憾,导航栏中没有显示任何按钮。 事实上,我什至无法为导航栏指定标题。我该如何解决这个问题?
谢谢
【问题讨论】:
标签: ios swift uinavigationcontroller uipageviewcontroller