我已经成功创建了两个带有四个按钮的警报。第一个 AlertView 效果很好,但第二个 alertView 让我崩溃了。这是我的代码:
-(void)showAlertWithTextField{
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"info" message:@"Set Time For The Game." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];
[alertView setTag:101];
alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
[[alertView textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alertView textFieldAtIndex:0] becomeFirstResponder];
[alertView show];
}
-(void)showexitAlertView
{
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Timeout" message:[NSString stringWithFormat:@"Your final score is: %i", runningSore] delegate:self cancelButtonTitle:@"Restart" otherButtonTitles:@"Exit", nil];
[alertView setTag:102];
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UITextField *field = [alertView textFieldAtIndex:0];
setTime = [field.text intValue];
NSLog(@"%d", setTime);
if (alertView.tag == 101 && buttonIndex == 0) {
//if (buttonIndex == 0){
NSLog(@"Ok");
[self setTimer];
[self countDownTimerPrepare];
[self countDownTimerIntro];
[self prepareForIntroAnimation];
[self performIntroAnimation];
[self categoriesList];
}
else if (buttonIndex == 1){
NSLog(@"Cancel");
ChooseViewController * controller = [[ChooseViewController alloc] initWithNibName:@"ChooseViewController" bundle:nil];
//controller.countdownLabel.text= score;
[self presentViewController:controller animated:YES completion:nil];
}
else if (alertView.tag==102 && buttonIndex == 0){
NSLog(@"Restart");
}
else if (buttonIndex == 1){
NSLog(@"Exit");
}
}
这是我在第二个警报视图中按下按钮时的 drbugging 消息:
2013-09-11 17:12:06.106 Diplomatiki [2808:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“textFieldIndex(0)超出了文本字段数组的范围”*第一次抛出调用stack: (0x1c42012 0x1737e7e 0x1c41deb 0xa7f0f0 0xb5d0 0xa72020 0x174b705 0x682920 0x6828b8 0x743671 0x743bcf 0x742d38 0x6b233f 0x6b2552 0x6903aa 0x681cf8 0x1fc2df9 0x1fc2ad0 0x1bb7bf5 0x1bb7962 0x1be8bb6 0x1be7f44 0x1be7e1b 0x1fc17e3 0x1fc1668 0x67f65c 0x29fd 0x2925 0x1) libc++abi.dylib: terminate called throwing an exception
我会感谢任何建议。先感谢您。