Iphone XCODE-如何:UIAlertView(带有文本字段)在循环中显示,直到在字段中输入正确的值为止?
我目前正在使用Xcode开发iOS应用程序 我已经设置了一个UIAlertView(以问题作为消息),以弹出一个文本字段来检索响应 所需的功能是,在文本字段中输入不正确的值时,UIAlert将循环。。。直到输入正确的响应。此时,UIAlert将被解除 这是我到目前为止所拥有的Iphone XCODE-如何:UIAlertView(带有文本字段)在循环中显示,直到在字段中输入正确的值为止?,iphone,objective-c,xcode,loops,uialertview,Iphone,Objective C,Xcode,Loops,Uialertview,我目前正在使用Xcode开发iOS应用程序 我已经设置了一个UIAlertView(以问题作为消息),以弹出一个文本字段来检索响应 所需的功能是,在文本字段中输入不正确的值时,UIAlert将循环。。。直到输入正确的响应。此时,UIAlert将被解除 这是我到目前为止所拥有的 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notificati
- (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];
}
}
我已经做了大量的谷歌搜索,但无法找到解决方案。。。任何回复都将不胜感激 试试这个
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *answerFieldString = answerField.text;
if ([answerFieldString isEqualToString: correctAnswer ])
{
[alertView dismissWithClickedButtonIndex:-1 animated:YES];
}
}
你为什么不编辑你的,而不是创建一个新的?