gpt4 book ai didi

ios - 在 performSegueWithIdentifier 之后不调用 prepareForSegue

转载 作者:搜寻专家 更新时间:2023-10-31 08:23:12 25 4
gpt4 key购买 nike

我是 iOS 开发新手。有很多重复的问题(抱歉)。但是我无法解决这个问题。

调用 performSegueWithIdentifier 后不会调用 prepareForSegue。

show segue 标识符被命名为“segue1”。Ctrl-从 ViewController 拖动到 DetailViewController。

我错过了什么吗?

ViewController.swift:

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

@IBAction func buttonTapped(sender: AnyObject) {
print("ViewController - buttonTapped()")
performSegueWithIdentifier("segue1", sender: self)
}

override func performSegueWithIdentifier(identifier: String, sender: AnyObject?) {
print("ViewController - performSegueWithIdentifier(): \(identifier)")
}

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
print("ViewController - shouldPerformSegueWithIdentifier()")
return true
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
print("ViewController - prepareForSegue(): \(segue.identifier!)")
}
}

DetailViewController.swift:

class DetailViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

print("DetailViewController - viewDidLoad()")
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}

这是一个screenshot of storyboard .

输出(点击按钮后)

ViewController - buttonTapped()
ViewController - performSegueWithIdentifier(): segue1

最佳答案

您没有调用 super - 添加以下内容以将消息发送到父类(这将依次触发 segue)

super.performSegueWithIdentifier(identifier, sender: sender)

关于ios - 在 performSegueWithIdentifier 之后不调用 prepareForSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33264435/

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