Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove UIAlertAction from UIAlertController in Swift?

I know you can disable UIAlertAction buttons in a UIAlertController, but is it possible to remove the button completely once it has been added?

like image 230
nb07 Avatar asked Mar 18 '16 15:03

nb07


1 Answers

It is not possible to remove actions from a UIAlertController once added.

The actions property can return an array of the added actions, but is a get only and can not be set.

Actions are added with the addAction(_:) method, but there is not a corresponding removeAction(_:) method.

And ultimately, it doesn't really necessarily make a lot of sense to be removing actions from an alert controller once added. You generally should be reusing the alert controller object once instantiated, so the solution is to simply only added the appropriate actions in the first place.

like image 181
nhgrif Avatar answered Sep 21 '22 18:09

nhgrif