UIAlertView easy way to tell if cancel button is selected

CodeGuy picture CodeGuy · Aug 3, 2011 · Viewed 19.3k times · Source

I know I've done this before but I just can't figure it out again.

What is the method I would use to see if a cancel button was pressed. I don't want to do it based on the button index. There is a way to do it, something like:

[alertView isCancelIndex:index];

Anyone know?

Answer

rich picture rich · Aug 3, 2011

The UIAlertView has a property of cancel button index

@property(nonatomic) NSInteger cancelButtonIndex

Usage

[alertView cancelButtonIndex]