views:

46

answers:

1

Hey guys,

Is there a way I can add a .tag to an UIAlertView button? Reason being, I'm adding a few dynamic buttons to the alert that will sometimes be in the alert and sometimes not. I figured the best way was to add a tag. Is there a better method for this?

The options that will ALWAYS be in the alert are Email, Save. And the 2 optional options are Tweet This and Facebook.

Thanks for any help in advance!

+1  A: 

There is one method buttonTitleAtIndex for UIAlertView. Use that to find the button tapped by user.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];
if( [buttonString isEqualToString:@"Facebook"] )
{
// your code here
}
else if( [buttonString isEqualToString:@"twitter"] )
{
// your code here
}
}

Anil Sivadas
That is PERFECT! I was going by the buttonIndex which isn't reliable. Thanks.
Raphael Caixeta