UIAlertView可以轻松判断是否选择了取消按钮

Cod*_*Guy 14 iphone uialertview ipad ios

我知道我以前做过这件事,但我再说不出来了.

我用什么方法来查看是否按下了取消按钮.我不想根据按钮索引来做.有一种方法可以做到这一点,例如:

[alertView isCancelIndex:index];
Run Code Online (Sandbox Code Playgroud)

谁知道?

ric*_*ich 52

UIAlertView具有取消按钮索引的属性

@property(nonatomic) NSInteger cancelButtonIndex
Run Code Online (Sandbox Code Playgroud)

用法

[alertView cancelButtonIndex]
Run Code Online (Sandbox Code Playgroud)


Ema*_*sid 32

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

  if (buttonIndex == [alertView cancelButtonIndex]) {
    NSLog(@"The cancel button was clicked for alertView");
  }
// else do your stuff for the rest of the buttons (firstOtherButtonIndex, secondOtherButtonIndex, etc)
}
Run Code Online (Sandbox Code Playgroud)