我目前正在iOS应用程序上使用Xcode ...
我已经设置了一个UIAlertView(带有问题作为信息),弹出一个文本字段来检索响应。
所需的功能是在文本字段中输入不正确的值后,UIAlert将循环...直到输入正确的响应。此时,UIAlert将被解雇。
到目前为止我所拥有的......
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
NSString* correctAnswer = @"2";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Alarm"
message:@"1 + 1 ="
delegate:self
cancelButtonTitle: nil
otherButtonTitles:@"Continue", nil ];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField* answerField = [alert textFieldAtIndex:0];
answerField.keyboardType = UIKeyboardTypeNumberPad;
answerField.placeholder = @"answer";
[alert show];
// I feel like this would work, but I know it doesn't...
NSString *answerFieldString = answerField.text;
if ([answerFieldString isEqualToString: correctAnswer ])
{
[alert dismissWithClickedButtonIndex:-1 animated:YES];
}
}
我已经进行了广泛的谷歌搜索,无法提出解决方案......任何回复都将非常感谢!
答案 0 :(得分:2)
试试这个......
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *answerFieldString = answerField.text;
if ([answerFieldString isEqualToString: correctAnswer ])
{
[alertView dismissWithClickedButtonIndex:-1 animated:YES];
}
}