我正在尝试使用 swift 的 shouldPerformSegueWithIdentifier() 方法,但它接受 2 个参数。这些是(标识符:String!,发件人:AnyObject)
我的主要目标是在我的 Storyboard中按下登录按钮时执行代码,并根据是否提供了正确的用户名和密码,根据一系列检查返回 TRUE 或 FALSE。所以这是我的问题:
我应该使用什么作为标识符? Apple 的文档解释说标识符是标识触发的 segue 的字符串。所以假设我的 segue 的名称是 loginSegueProcess。我如何在分配给 UIView 的 ViewController 中使用它?问题是我在我的代码中声明了该方法,它要求我指定两个参数(标识符和发送者)。我如何提供论据?
这种方法真的能满足我的需求吗?我的意思是,如果它确实会在单击我的登录按钮时停止 segue 转换,并且取决于是否提供了正确的凭据,它将带您到下一个 View 或者它会显示,例如,一个 AlertView。
最后,我认为 performSegueWithIdentifier(args) 方法也会对我有所帮助。有人知道它们之间的区别吗?
提前致谢!
最佳答案
这不是你想做的吗?
override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool {
if identifier == "LoginSuccessSegue" { // you define it in the storyboard (click on the segue, then Attributes' inspector > Identifier
var segueShouldOccur = /** do whatever you need to set this var to true or false */
if !segueShouldOccur {
println("*** NOPE, segue wont occur")
return false
}
else {
println("*** YEP, segue will occur")
}
}
// by default, transition
return true
}
关于iphone - 在 Swift 中使用 shouldPerformSegueWithIdentifier( ) 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25113602/