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?
The UIAlertView has a property of cancel button index
@property(nonatomic) NSInteger cancelButtonIndex
Usage
[alertView cancelButtonIndex]
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == [alertView cancelButtonIndex]) {
NSLog(@"The cancel button was clicked for alertView");
}
// else do your stuff for the rest of the buttons (firstOtherButtonIndex, secondOtherButtonIndex, etc)
}
In the delegate of UIAlertView is the method
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
And then:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSInteger cancelIndex = [alertView cancelButtonIndex];
if (cancelIndex != -1 && cancelIndex == buttonIndex)
{
// Do something...
}
}
精彩评论