gpt4 book ai didi

swift 准备(: segue) not called

转载 作者:行者123 更新时间:2023-12-04 15:38:04 28 4
gpt4 key购买 nike

在我的 Storyboard中,controller1 有 natigationController 和 segues 到 controller 2。奇怪的是 Segue 工作正常但是

override 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
}
}

最佳答案

您正在 self.navigationController 上调用 performSegue,因此将调用 navigationController.prepareForSegue,而不是您的 VC 中的那个.您应该将 segue 重新连接到 Storyboard中的您的 VC,为其提供标识符,然后调用:

self.performSegue(...)

关于 swift 准备(: segue) not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59092877/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com