【问题标题】:Reload View after UIAlertController在 UIAlertController 之后重新加载视图
【发布时间】:2017-02-15 13:50:45
【问题描述】:

我有一个带有电话号码字段的注册屏幕。 如果用户输入的电话号码太短,我会显示一个 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)
}

【问题讨论】:

  • 有办法重载视图有什么用这个你要重载什么
  • 重新加载什么视图?输入视图的代码是什么?它是一个简单的 UIView 吗?一个 UIButton?一个 UITableView?
  • 如果您想知道用户何时单击“确定”按钮,只需分配一个处理程序而不是将其设置为nil
  • 这是一个 UIViewController。这是截图imgur.com/a/tFwvy
  • 你在哪里调用了这个函数 present_alert(title:String, content : String)

标签: ios swift xcode swift3 uialertcontroller


【解决方案1】:

单击按钮的主要原因是您禁用了您的按钮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)

【讨论】:

  • addyourbuttonName.isEnabled = true 用于启用您的按钮
【解决方案2】:
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
    }
}

【讨论】:

    【解决方案3】:

    据我了解您的问题是您的按钮 false 参数“isEnabled”的值。要解决这个问题,只需将最后一个字符串添加到您的块中:

    buttonName.isEnabled = true
    

    【讨论】:

      【解决方案4】:

      点击 UIAlertAction(cancel or ok) 后,您可以在该 ok 或 cancel 方法中添加一些功能。在该方法的最后一步,添加 viewWillAppear(true) 方法。然后 UIViewController 会自动刷新。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-23
        • 2018-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-08
        • 1970-01-01
        相关资源
        最近更新 更多