UIAlertView已被弃用.您现在可以使用UIAlertController,如here所述.
您可以创建这样的UIAlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really reset?"
message:@"Do you really want to reset this game?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"reset", nil];
[alert show];
要处理AlertView按钮单击,您必须
@interface YourViewController:UIViewController<UIAlertViewDelegate>{
.......
.......
}
然后是implementUIAlertViewDelegate
个协议方法,
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == [alertView cancelButtonIndex]){
//cancel clicked ...do your action
}else{
//reset clicked
}
}