在 UIAlertController 之后重新加载视图
Reload View after UIAlertController
我有一个带有 phone 数字字段的注册屏幕。
如果用户键入太短的 phone 数字,我会显示一个 UIAlertController。
在她关闭警报后,用户无法再次发送她的 phone 号码,因为点击了发送按钮。
有没有办法在解除警报以使按钮未被点击时重新加载视图?
谢谢
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)
}
点击按钮的主要原因是您禁用了您的按钮 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)
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
}
}
据我了解您的问题,问题是您收到了参数 "isEnabled" 的按钮 false 值。要解决这个问题,只需将最后一个字符串添加到您的块中:
buttonName.isEnabled = true
点击 UIAlertAction(cancel 或 ok) 后,您可以在该 ok 或 cancel 方法中添加一些功能。在该方法的最后一步,添加 viewWillAppear(true) 方法。然后UIViewController自动刷新。
我有一个带有 phone 数字字段的注册屏幕。 如果用户键入太短的 phone 数字,我会显示一个 UIAlertController。 在她关闭警报后,用户无法再次发送她的 phone 号码,因为点击了发送按钮。 有没有办法在解除警报以使按钮未被点击时重新加载视图? 谢谢
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)
}
点击按钮的主要原因是您禁用了您的按钮 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)
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
}
}
据我了解您的问题,问题是您收到了参数 "isEnabled" 的按钮 false 值。要解决这个问题,只需将最后一个字符串添加到您的块中:
buttonName.isEnabled = true
点击 UIAlertAction(cancel 或 ok) 后,您可以在该 ok 或 cancel 方法中添加一些功能。在该方法的最后一步,添加 viewWillAppear(true) 方法。然后UIViewController自动刷新。