我從我的添加欄按鈕項下面的代碼中調用了我提供的警報視圖,詢問用戶輸入。它工作正常,第一次,並給後出現以下錯誤: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