Sujeev's Tech Blog

Monday, January 03, 2011

UIAlertView and its delegate

Following is the normal use of UIAlertView

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msgTitle message:soapResults delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

but lets say if we want to do some processing after a UIAlertView is dismissed, then to accomplish this,

first add a UIAlertViewDelegate to the viewController.
second use the following.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msgTitle message:soapResults delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert setTag:127];
[alert show];

[alert release];

- (
void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if ([alertView tag] == 127) {    
if (buttonIndex == 0) {
// do stuff
}
}
}


in the above code note the UIAlertView tag used as a identifier when there are more than one UIAlertViews

0 Comments:

Post a Comment

<< Home