导航项目未添加

时间:2017-07-09 10:44:08

标签: swift3 uinavigationcontroller uinavigationbar uinavigationitem

我在UINavigationBar上添加了两个按钮。我能够成功呈现导航控制器但不添加按钮。

let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "FilterViewController") as! FilterViewController
        let navigationVC = UINavigationController(rootViewController: secondVC)
        navigationVC.navigationBar.tintColor = UIColor.red
        navigationVC.navigationBar.topItem?.title = "some title"
        navigationVC.navigationBar.isTranslucent = false

        let add = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(dismissFilterView))
        let play = UIBarButtonItem(title: "Play", style: .plain, target: self, action: #selector(dismissFilterView))

        navigationVC.navigationItem.rightBarButtonItems = [add, play]
        self.present(navigationVC, animated: true, completion: nil)

enter image description here

1 个答案:

答案 0 :(得分:1)

它无效,因为您在导航栏中添加了导航项。添加ViewController的导航项。

替换

navigationVC.navigationItem.rightBarButtonItems = [add, play]

secondVC.navigationItem.rightBarButtonItems = [add, play]

enter image description here