0

I am new to Swift, and I have questions regarding how to present Alert Window one by one after the user clicks the button(dismiss). So I could have the second the window pops out right after users click the button to dismiss the alert? So far, I tried I can't display them together by trying:

  self.createAlert(title: " 1", message: "1")
  self.createAlert(title: " 2",message: "2")

And I would get error message:

[Presentation] Attempt to present <UIAlertController: 0x7f9e4380b800> on <UITabBarController: 0x7f9e43059000> (from <IFTTT.HomePageViewController: 0x7f9e41c17be0>) which is already presenting <UIAlertController: 0x7f9e4280b000>.

Can someone introduce me to some techniques to solve this? Like a boolean function to know if the last window is closed or something more efficient. Thank you!!

siiulan
  • 55
  • 6
  • Does this answer your question? [How would I create a UIAlertView in Swift?](https://stackoverflow.com/questions/24022479/how-would-i-create-a-uialertview-in-swift) – Harshil Patel Nov 12 '20 at 23:55

1 Answers1

1

When the user taps a button in an alert to dismiss it, you get called in that button's action handler:

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: {
    // what goes here?
})) 

The code in "what goes here?" is called after the alert is dismissed, so that is your chance to present another alert immediately.

matt
  • 515,959
  • 87
  • 875
  • 1,141