0
func showAlert(...) {
    let alertController = UIAlertController(...)

    let add = UIAlertAction(title: "Add", style: .default) { (action) in
        onAdd?()
    }

    alertController.addAction(ok)

    ...
}

I would like to keep the popup alert after click on Add. But it seem iOS will auto close the popup. How to make it work?

zs2020
  • 53,766
  • 29
  • 154
  • 219
  • If you don't want it dismissed, it may be easier to do with just a set of views that you hide or show as part of the underlying view controller logic. – Phillip Mills Dec 27 '18 at 01:51
  • Possible duplicate of [Prevent UIAlertController to dismiss](https://stackoverflow.com/questions/28919670/prevent-uialertcontroller-to-dismiss) – nayem Dec 27 '18 at 02:19
  • Possible duplicate of [Prevent dismissal of UIAlertController](https://stackoverflow.com/q/25628000/3687801) – nayem Dec 27 '18 at 02:20

1 Answers1

1

The only way to prevent a UIAlertController's alert from being dismissed when a button is tapped is to disable the button.

If you don't like that, don't use UIAlertController; use your own presented view controller. That's all a UIAlertController is, after all. So it's easy to write your own if you need to.

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