我想在场景之间进行条件segue,这样只有在满足条件时才会发生.问题是,当我点击激活此segue的按钮时,它会执行segue而不关心是否满足条件.这是代码:
@IBAction func goonbutton(sender: UIButton) { if textFieldRandomWord.text !=nil { performSegueWithIdentifier("firstsegue", sender: sender) } else { whateverLabel.text = "You didn't actually write anything." } }
所以我希望segue仅在textFieldRandomWord!= nil时出现.任何帮助将不胜感激!
你想要做的是实现如下:
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { if identifier == "WhateverYourSegueIsNamed" { // you define it in the storyboard (click on the segue, then Attributes' inspector > Identifier if textFieldRandomWord.text.isEmpty == true { print("*** NOPE, segue wont occur") return false } else { print("*** YEP, segue will occur") } } // by default, transition return true }
我在这个相关问题的答案中可以看到我对这个伟大例子的回答