我目前正在 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];
}
}
我已经进行了大量的谷歌搜索,但无法找到解决方案...任何回复将不胜感激!
最佳答案
试试这个...
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *answerFieldString = answerField.text;
if ([answerFieldString isEqualToString: correctAnswer ])
{
[alertView dismissWithClickedButtonIndex:-1 animated:YES];
}
}
关于iphone - XCODE - 如何 : UIAlertView (with a text field) on a loop until correct value entered into field?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9407338/