我正在尝试向UI警报添加“确定”按钮,但我无法使用alertController.addAction添加它
在这种情况下我该怎么办?
提前致谢!!
if error == nil {
let alert: UIAlertController = UIAlertController(title: "Account Created", message: "Please confirm your email", preferredStyle: .Alert)
let okButton = UIAlertAction(title: "Ok", style: .Default) { action -> Void in
self.performSegueWithIdentifier("toMain", sender: self)
alertController.addAction(okButton)
self.presentViewController(alert, animated: true, completion: nil)
}
} else {
println("\(error)")
}
答案 0 :(得分:1)
alert
代替alertController
alert.addAction
应该在okbutton
行动之外。使用以下代码更改您的代码:
if error == nil {
let alert: UIAlertController = UIAlertController(title: "Account Created", message: "Please confirm your email", preferredStyle: .Alert)
let okButton = UIAlertAction(title: "Ok", style: .Default) { action -> Void in
self.performSegueWithIdentifier("toMain", sender: self)
}
alert.addAction(okButton)
self.presentViewController(alert, animated: true, completion: nil)
} else {
println("\(error)")
}