Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

otherButtonTitles in UIAlertView

I was just curious about how can i attach some different task to the otherButtonTitle of UIAlertView. The cancel button automatically take you out of the application but if i want to attach a different task with the otherButtonTitle ,what should i do?

Thanks,

like image 612
Ashutosh Avatar asked Jul 23 '10 04:07

Ashutosh


1 Answers

UIAlertView delegate "didDismissWithButtonIndex" get called every time u click any button.

Try this:

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" 
                                                message:messageString
                                               delegate:self 
                                      cancelButtonTitle:@"Back"
                                      otherButtonTitles:@"Reply",@"Delete",nil];
[alert show];
[alert release];


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{
  if (buttonIndex == 1)
  {
    NSLog(@"Reply");
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Reply " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [myalert show];
    [myalert release];  
  }

  if (buttonIndex == 2)
  {
    NSLog(@"Delete");
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Delete " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [myalert show];
    [myalert release];  
  }
}
like image 81
iPhoneDev Avatar answered Oct 25 '22 13:10

iPhoneDev