2017-02-15 117 views
0

我有一個電話號碼字段的註冊屏幕。 如果用戶輸入一個太短的電話號碼,我會顯示一個UIAlertController。 她拒絕了警報後,用戶無法再次發送她的電話號碼,因爲發送按鈕被點擊。 有沒有辦法重新加載視圖時,警報被解僱,使按鈕重置? 感謝UIAlertController後重新加載視圖

func present_alert(title:String, content : String){ 
    let myAlert = UIAlertController(title:title, message:content, preferredStyle:UIAlertControllerStyle.alert) 
    let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler:nil) 
    myAlert.addAction(okAction) 
    self.present(myAlert, animated:true) 
} 
+0

有沒有辦法重新加載的觀點是什麼,你想要什麼用的這個重載 –

+0

刷新有什麼看法?輸入視圖的代碼是什麼?這是一個簡單的UIView嗎?一個UIButton?一個UITableView? – 2017-02-15 13:52:56

+0

如果您想知道用戶何時單擊「確定」按鈕,只需指定一個處理程序,而不是將其設置爲「nil」。 – redent84

回答

2

按鈕的主要原因單擊禁用yourbutton sender.isEnabled = false,當過警報再次呈現啓用按鈕,肯定工作addyourbuttonName.isEnabled = true

,如果你想清除當前的文本框的值,然後使用yourtextfield.text = ""

let alertController = UIAlertController(title: 「Simple」, message: 「Simple alertView demo with Cancel and Ok.」, preferredStyle: UIAlertControllerStyle.alert) 

let okAction = UIAlertAction(title: 「OK」, style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in 
print(「OK」) 
yourtextfield.text = "" 
yourtextfield.becomeFirstResponder() 
addyourbuttonName.isEnabled = true 
} 


alertController.addAction(okAction) 
self.present(alertController, animated: true, completion: nil) 
+0

'addyourbuttonName.isEnabled = true'用於啓用您的按鈕 –

+0

檢查更新的答案 –

0
func present_alert(title:String, content:String, button:UIButton){ 
    let myAlert = UIAlertController(title:title, message:content, preferredStyle:UIAlertControllerStyle.alert) 
    let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler:nil) 
    myAlert.addAction(okAction) 
    self.present(myAlert, animated:true){ 
     button.isEnabled = true 
    } 
} 
0

據我瞭解您的問題問題是個在您收到您的按鈕false參數值「isEnabled」。爲了解決這個問題只需添加到您的阻止最後一個字符串:

buttonName.isEnabled = true