我有一個UIAlertController
,我正在檢查用戶輸入。當用戶沒有輸入文本字段時,我添加的OK Action按鈕應該給用戶一個警告並且不關閉警報視圖。如何禁用UIAlertController按動作按鈕時自動關閉
我處理警告,但警報視圖自動關閉。 我如何禁用自動關閉?
謝謝。
我的代碼:
var alert = UIAlertController(title: "change name and phone number", message: nil, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,
handler: { action in
//Add a comment to this line
let nameField: UITextField = alert.textFields![0] as UITextField
let phoneField: UITextField = alert.textFields![1] as UITextField
let name = nameField.text
let phone = phoneField.text
if name.length == 0 {
JLToast.makeText("Please enter name").show()
} else if phone.length == 0 {
JLToast.makeText("Please enter phone number").show()
} else {
self.sendSupportInfo(nameField.text, phone: phoneField.text)
}
println("name:: \(nameField.text), phone: \(phoneField.text)")
}))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
alert.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "name"
}
alert.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "0544-444444"
textField.keyboardType = UIKeyboardType.PhonePad
}
self.presentViewController(alert, animated: true, completion: nil)
[阻止UIAlertController關閉]的可能重複(http://stackoverflow.com/questions/28919670/prevent-uialertcontroller-to-dismiss) – soulshined 2015-04-02 20:52:59