呈现页面时出现UiNavigation错误

时间:2018-06-10 13:44:08

标签: ios swift uinavigationcontroller

我正在编写Swift 在我的代码的这一部分中,它应该在选择表格中的单元格时打开一个viewcontroller。

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


    let next = self.storyboard?.instantiateViewController(withIdentifier: "SVC")
    self.navigationController?.pushViewController(next!, animated: true)
    self.present(next!, animated: true, completion: nil)

}

它返回错误!!

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:'应用程序试图呈现   模块化一个活动控制器

当我运行它时它工作正常但当它打开特定的viewcontroller它崩溃和屏幕冻结

1 个答案:

答案 0 :(得分:1)

你应该使用这个

self.navigationController?.pushViewController(next!, animated: true)

或者

 self.present(next!, animated: true, completion: nil)

修改:使用此

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let next = self.storyboard?.instantiateViewController(withIdentifier: "SVC")
    self.navigationController?.pushViewController(next!, animated: true) 
}
相关问题