在我的情节提要中,controller1具有natigationController并与控制器2相连。很奇怪,Segue可以正常工作,但
覆盖func prepare(for:segue)
没有调用整个方法(我设置了断点)。我复习了许多关于stackoverflow的老问题,但是没人能解决我的问题。谢谢!
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
self.navigationController?.performSegue(withIdentifier: segueId, sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == self.segueId {
let destionationNVC = segue.destination as! UINavigationController
guard let targetVC = destionationNVC.topViewController as? ViewController2 else { return }
targetVC.text = self.text
}
}
performSegue
上的self.navigationController
,因此将被调用的是navigationController.prepareForSegue
,而不是VC中的那个。您应该将故事服务器重新连接到情节提要中的您的VC,为其提供标识符,然后调用:
self.performSegue(...)