我从我的添加栏按钮项中调用以下代码,我在其中显示警报 View 以请求用户输入。它第一次运行良好,之后出现以下错误:
代码:
var alert = UIAlertController(title: "Enter Blog Link", message: nil, preferredStyle: .Alert)
func userBlogLinkEntryPopover() {
// let alert = UIAlertView(title: "Enter Blog Link", message: nil, delegate: self, cancelButtonTitle: "Cancel")
alert.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "Enter Blog URL!"
}
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
if let tf = self.alert.textFields?.first as? UITextField{
println(tf.text)
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
presentViewController(alert, animated: true, completion: nil)
}
Error : 'UIAlertController can only have one action with a style of UIAlertActionStyleCancel'
我认为每次按下添加按钮时它都会尝试添加操作,因此会出现错误。如果我错了,请纠正我,也请提出解决方法。
感谢您的帮助。
最佳答案
如果你这样做你也会得到这个,仔细阅读看看你是否能看到错误
resendAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
//cancel clicked
return
}))
resendAlert.addAction(UIAlertAction(title: "Check Server", style: .cancel, handler: { (action: UIAlertAction!) in
//check server clicked
return
}))
注意---> .cancel
不被使用两次它需要是.default
在第二个
resendAlert.addAction(UIAlertAction(title: "Check Server", style: .default, handler: { (action: UIAlertAction!) in
//check server clicked
return
}))
工作正常
关于swift - UIAlertController 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29592522/