为什么我的代码无法打开导航控制器?

时间:2018-06-26 00:06:41

标签: swift xcode uinavigationcontroller

为什么按下相机按钮时以下代码无法打开导航控制器?完成的功能指定相机应推动视图控制器,但什么也没发生。

func setNavigationBar() {
let screenSize: CGRect = UIScreen.main.bounds
let navBar = UINavigationBar(frame: CGRect(x: 0, y: 20, width: screenSize.width, height: 160))
let navItem = UINavigationItem(title: "Hello")
let doneItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.camera, target: self, action: #selector(done))
navItem.rightBarButtonItem = doneItem
navBar.setItems([navItem], animated: false)
self.view.addSubview(navBar)
}

@objc func done() { // remove @objc for Swift 3
let dummyViewController = UIViewController()
navigationController?.pushViewController(dummyViewController, animated: true)

}

0 个答案:

没有答案