How to react to multiple UIAlertViews

If your class creates more than one UIAlertView, then you need a way to react to each of those accordingly. Problem is, you may only have one delegate that listens to all alerts at any given time.

You could of course create a separate class for each alert view, but that’s a bit overkill. Instead, the UIView’s tag property comes in handy with which you can identify a view at runtime (and UIAlertView inherits from UIView).

tag is an integer so you can only give it whole numbers, like so:

In your delegate method you can now ask which tag is set when those buttons are pressed:

See also:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.