-1

I'm trying to make an app where you can click to book a reservation. When you click on the button of the reservation you want, an UIAlert will show up and ask if you want to confirm the action. If so, then another UIAlert will show up and confirm your reservation.

I'm having difficulties to understand how to make this series os UIAlerts. Here's the code.

 @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()
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Lucas Leal
  • 245
  • 1
  • 2
  • 8
  • 1
    Use `UIAlertController` instead of `UIAlertView` if you are targeting iOS 8.0 or later. – Tamás Sengel Jul 22 '17 at 15:02
  • 1
    You should probably be using [UIAlertController](https://developer.apple.com/documentation/uikit/uialertcontroller) because UIAlertView is deprecated – allenh Jul 22 '17 at 15:02
  • 1
    Possible duplicate of [How to add an action to a UIAlertView button using Swift iOS](https://stackoverflow.com/questions/24195310/how-to-add-an-action-to-a-uialertview-button-using-swift-ios) – Tamás Sengel Jul 22 '17 at 15:03
  • Thanks for the help guys, it was really a duplicate of the one you showed up here. Updated to UIAlertController – Lucas Leal Jul 23 '17 at 16:03

1 Answers1

0

You should use UIAlertController as stated for some in the comments.

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

And add an actions (buttons) as required

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)

As shown you must create the code to process the response in the handler, including creating the new alert.

rmaddy
  • 314,917
  • 42
  • 532
  • 579