【问题标题】:create a new UIAlert based on a previous UIAlert's button click根据之前的 UIAlert 按钮单击创建一个新的 UIAlert
【发布时间】:2017-07-22 14:59:06
【问题描述】:

我正在尝试制作一个应用程序,您可以在其中单击以进行预订。当您单击所需的预订按钮时,将显示 UIAlert 并询问您是否要确认操作。如果是这样,则会显示另一个 UIAlert 并确认您的预订。

我很难理解如何制作这个系列操作系统 UIAlerts。这是代码。

 @IBAction func garageinn(_ sender: Any) {

    var refreshAlert = UIAlertView()
    refreshAlert.title = "Book a vacancy?"
    refreshAlert.message = "A vacancy will be reserved at Garage Inn."
    refreshAlert.addButton(withTitle: "Cancel")
    refreshAlert.addButton(withTitle: "Ok")
    refreshAlert.show()
}

【问题讨论】:

标签: swift


【解决方案1】:

您应该按照 cmets 中的说明使用 UIAlertController。

let alert : UIAlertController = UIAlertController(title: "title", message: "message", preferredStyle: .alert)

并根据需要添加操作(按钮)

let accept : UIAlertAction = UIAlertAction(title: "Accept", style: UIAlertActionStyle.default, handler: {
    // -code to process- and -create new alert-
})

let cancel : UIAlertAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)

如图所示,您必须创建代码来处理处理程序中的响应,包括创建新警报。

【讨论】:

  • 很高兴知道,请选择作为答案;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多