简体   繁体   English

在 UIAlertController 之后重新加载视图

[英]Reload View after UIAlertController

I have a signup screen with a phone number field.我有一个带有电话号码字段的注册屏幕。 If the user type a too short phone number, I display an UIAlertController.如果用户输入的电话号码太短,我会显示一个 UIAlertController。 After she dismisses the Alert, the user can't send her phone number again as the send button is tapped.在她解除警报后,用户无法再次发送她的电话号码,因为点击了发送按钮。 Is there a way to reload the view when the alert is dismissed to make the button untapped?有没有办法在解除警报时重新加载视图以使按钮未点击? Thanks谢谢

    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)
}

the main reason on button click you disabled the yourbutton sender.isEnabled = false , when ever the alert is presented again enable your button , surely works addyourbuttonName.isEnabled = true单击按钮的主要原因是您禁用了 yourbutton sender.isEnabled = false ,当再次出现警报时启用您的按钮,肯定可以使用addyourbuttonName.isEnabled = true

if you want to clear the current textfield value then use yourtextfield.text = ""如果要清除当前文本字段值,请使用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)
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
    }
}

As i understand your issue the problem is that you receive your button false value of parameter "isEnabled".据我了解您的问题,问题是您收到参数“isEnabled”的按钮错误值。 To fix that just add to your block last string:要解决这个问题,只需添加到您的块最后一个字符串:

buttonName.isEnabled = true

After click on UIAlertAction(cancel or ok), you can add some functionality in that ok or cancel method.单击 UIAlertAction(cancel or ok) 后,您可以在该 ok 或 cancel 方法中添加一些功能。 In the final step of that method, add viewWillAppear(true) method.在该方法的最后一步,添加 viewWillAppear(true) 方法。 Then UIViewController automatically refresh.然后 UIViewController 自动刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM