我有以下代码,当用户注册时会显示一个警告框。在用户与Alert Box按钮交互之后(即我们离开),我有一个需要触发的segue(现在称为someSegue),以便它可以将用户重定向到登录页面。
用户点击警告框按钮后没有任何事情发生。我错过了什么?是自我吗?如果我删除自己它不起作用,xcode抱怨。
user.signUpInBackgroundWithBlock {
(succeeded, error) -> Void in
if error == nil {
// Hooray! Let them use the app now.
let delay = 4.5 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {
actInd.stopAnimating()
var alert = UIAlertController(title: "Congratulations!", message: "Your account was successfully created! You will be required to login with your credentials.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Let's Go!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
self.performSegueWithIdentifier("someSegue", sender: self)
}
} else {
// Show the errorString somewhere and let the user try again.
}
}
答案 0 :(得分:0)
如果要在按下警告按钮后执行代码块,则需要在addAction方法的handler参数中传递该块
alert.addAction(UIAlertAction(title: "Let's Go!", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in
self.performSegueWithIdentifier("someSegue", sender: self)
}))