gpt4 book ai didi

iphone - XCODE - 如何 : UIAlertView (with a text field) on a loop until correct value entered into field?

转载 作者:行者123 更新时间:2023-12-03 21:03:59 24 4
gpt4 key购买 nike

我目前正在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com