我从我的添加栏按钮项下面的代码中调用了我提供的警报视图,询问用户输入。它工作正常,第一次,并给后出现以下错误:UIAlertController错误
代码:
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)
}
错误:“UIAlertController只能用 UIAlertActionStyleCancel风格一个动作”
我认为每次按下添加按钮时都会尝试添加操作,因此会出现错误。请纠正我,如果我错了,也请建议工作。
感谢您的帮助。
为什么您将'var alert'声明从函数'userBlogLinkEntryPopover'移出?把它放回去。警报不需要是属性。 – matt