UIAlertView中的otherButtonTitles

时间:2010-07-23 04:39:12

标签: objective-c uialertview

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

谢谢,

1 个答案:

答案 0 :(得分: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];  
  }
}