我是iOS开发的新手。有许多重复的问题(抱歉)。但我无法解决这个问题。
调用performSegueWithIdentifier后不会调用prepareForSegue。
show segue标识符命名为' segue1'。 从ViewController按Ctrl键拖动到DetailViewController。
我错过了什么吗?
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!)")
}
}
class DetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("DetailViewController - viewDidLoad()")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
ViewController - buttonTapped()
ViewController - performSegueWithIdentifier(): segue1
答案 0 :(得分:5)
你没有调用超级 - 添加以下内容将消息发送给父类(这将反过来激活segue)
super.performSegueWithIdentifier(identifier, sender: sender)