代码之家  ›  专栏  ›  技术社区  ›  Ashutosh

UIAlertView中的其他按钮图标

  •  9
  • Ashutosh  · 技术社区  · 16 年前

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

    1 回复  |  直到 16 年前
        1
  •  22
  •   Dan J Akhil    14 年前

    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];  
      }
    }
    
    推荐文章