【发布时间】:2018-01-19 16:32:37
【问题描述】:
我已经阅读了一些答案,例如关闭当前的 ViewController,但我的情况有所不同,因为我正在展示另一个 ViewController。
虽然我无法访问它的属性,但这段代码向视图控制器展示了它的导航控制器:
@IBAction func didTouchAddFriend(_ sender: UIButton) {
DispatchQueue.main.async {
let storyBoard = UIStoryboard(name: "CustomContact", bundle: nil)
let customContactVC = storyBoard.instantiateViewController(withIdentifier: "CustomContact")
}
}
虽然这个不起作用
@IBAction func didTouchAddFriend(_ sender: UIButton) {
DispatchQueue.main.async {
let navigation = UIStoryboard.init(name: "CustomContact", bundle: nil).instantiateInitialViewController() as! UINavigationController
let pickerUserVC = navigation.viewControllers.first as! CustomContactsViewController
self.present(pickerUserVC, animated: true, completion: nil)
}
}
我有另一个名为 CustomContact.storyboard 的故事板,其中包含一个 CustomContactsViewController
当我点击 didTouchAddFriend 时,它只显示这个错误:
'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <Main.MainViewController: 0x7ff29f06ac00>.'
当我打印 pickerUserVC 的值时,我无法理解错误 cos,它显示了正确的视图控制器:
<Main.CustomContactsViewController: 0x7fd1b7922400>
MainViewController 是当前实现 didTouchAddFriend 函数的视图控制器
【问题讨论】: