我正在尝试向UIDocumentBrowserViewController
添加自定义栏按钮项。我可以使用数组属性additionalLeadingNavigationBarButtonItems
添加自定义栏项目。我可以在运行应用程序时触发此按钮,但是,此外,当我触发按钮时,我想将新的视图控制器推入UIDocumentBrowserViewController
的导航堆栈中。有一个UIDocumentBrowserViewController
。navigationController属性,但是当我运行该程序时此属性为nil。有没有正确的方法来访问与UIDocumentBrowserViewController
关联的navigationController以及从条形按钮推入新视图控制器的正确方法是什么?谢谢
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
allowsDocumentCreation = true
allowsPickingMultipleItems = false
let barButton = UIBarButtonItem.init(title: "⚙︎", style: .plain, target: self, action: #selector(browserSettings))
additionalLeadingNavigationBarButtonItems = [barButton]
}
@objc func browserSettings() {
print("in browserSettings")
let settingViewController = HelpViewController()
settingViewController.setupView()
settingViewController.textView.text = "hello"
settingViewController.textView.contentOffset = CGPoint.zero
let navController = self.navigationController
navController?.pushViewController(settingViewController, animated: true)
//navController is nil??
}
当我触发按钮时,程序仅打印 “在browserSettings中” navController为零
答案 0 :(得分:0)
尝试一下
@objc func browserSettings() {
print("in browserSettings")
let settingViewController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "StoryboardID") as! HelpViewController
settingViewController.textView.text = "hello"
settingViewController.textView.contentOffset = CGPoint.zero
self.navigationController?.pushViewController(settingViewController, animated: true)
}
并将Navigation Controller
添加到UIViewController
中的Main.Storyboard