【问题标题】:UIAlertcontroller as an action in SwiftUIAlertcontroller 作为 Swift 中的一个动作
【发布时间】:2015-01-10 19:57:27
【问题描述】:

所以我希望弹出一个警报告诉我一条消息,然后我希望它等待我,直到我按 OK,然后它将继续使用该功能。例如。

@IBAction Alert() {
    let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
    alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alertController, animated: true, completion: nil)
}

问题是现在它什么都不会做,如果我只是在之后输入一个函数,它会直接执行它,而不是等到我按下确定。有谁知道怎么做?

顺便说一句,在这个例子中,消息是标题,消息,我知道这不是我在这种情况下需要的;)

提前致谢!

【问题讨论】:

  • 你的意思是你需要在按下确定按钮后执行一个任务?
  • 没错@MidhunMP

标签: ios swift uialertcontroller


【解决方案1】:

您需要将代码放入 OK 按钮处理程序中,而不是将 nil 放在那里。

修改代码:

@IBAction func Alert()
{
   let alertController = UIAlertController(title: title, message: message, preferredStyle:UIAlertControllerStyle.Alert)

   alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default)
   { action -> Void in
     // Put your code here
   })
   self.presentViewController(alertController, animated: true, completion: nil)

}

【讨论】:

    【解决方案2】:
    let alertController = UIAlertController(title: "Alert", message: "Please fill Bill Total, Select Tip, Choose Split", preferredStyle:.alert)
    
    alertController.addAction(UIAlertAction(title: "OK", style: .default)
              { action -> Void in
                // Put your code here
              })
    self.present(alertController, animated: true, completion: nil)
    

    【讨论】:

      猜你喜欢
      • 2017-03-04
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多