UIAlertView中的otherButtonTitles

Ash*_*osh 9 objective-c uialertview

我只是好奇我怎么能将一些不同的任务附加到UIAlertView的otherButtonTitle.取消按钮会自动将您带出应用程序,但如果我想使用otherButtonTitle附加不同的任务,我该怎么办?

谢谢,

iPh*_*Dev 22

每次单击任何按钮时,都会调用UIAlertView委托"didDismissWithButtonIndex".

试试这个:

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];  
  }
}
Run Code Online (Sandbox Code Playgroud)