I have controller which implements UIAlertViewDelegate. In implementation I have:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
method. When I create UIAlertView I put for 'delegate' to 'self' and it works fine. But problem is that now I have one more alert views and I want different behaviors for each of them. So how to check which alertView send message?
UIAlertView is a UIView subsclass and so has tag property you can use to differentiate between them:
UIAlertView *alert1 = ... //Create alert
alert1.tag = kActionTag1;
//show alert
...
UIAlertView *alert2 = ... //Create alert
alert2.tag = kActionTag2;
//show alert
And then in delegate method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == kActionTag1){
// Perform 1st action
}
if (alertView.tag == kActionTag1){
// Perform 2nd action
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With