我有一个UIAlertView
带有 2 个按钮的重新加载按钮 - 确定和取消。取消按钮工作正常,但是当我想在 OK 按钮中放置一些操作(再次玩游戏)时不起作用,除非该操作是NSLog
.
我的代码在 m 中。文件:
- (IBAction)startAgainAction:(id)sender {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Warning" message:@"Have you short that want start again the game?"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// My OK button
if (buttonIndex == alertView.cancelButtonIndex) {
// Action to start the game again... (don't work)
[self viewDidLoad];
} else if (buttonIndex == alertView.firstOtherButtonIndex) {
// NSLog it's accept but not other actions...
NSLog(@"Cancel");
}
}
是的,我已将UIAlertViewDelegate
协议放入 h. 文件
那么,为什么viewDidLoad
再次调用该方法时不起作用?