Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertViewDelegate and more Alert windows

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?

like image 984
1110 Avatar asked Dec 03 '10 14:12

1110


1 Answers

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
     }
}
like image 157
Vladimir Avatar answered Oct 04 '22 16:10

Vladimir