gpt4 book ai didi

ios - 验证失败后提示用户再次通过 UIAlertController 输入内容会在日志上显示警告

转载 作者:行者123 更新时间:2023-11-30 13:50:42 25 4
gpt4 key购买 nike

我正在使用以下函数提示用户输入电子邮件地址。如果验证失败,validateEmailAddress 和 validateVerificationCodeAgainstEmail 会再次调用下面的函数,promptUserToEnterEmail。问题是,当再次提示用户时,我收到如下所示的警告消息。

func promptUserToEnterEmail() {

var alertController:UIAlertController?
alertController = UIAlertController(title: "Enter Email Address",
message: "Please enter your email address.",
preferredStyle: .Alert)

alertController!.addTextFieldWithConfigurationHandler(
{(textField: UITextField!) in
textField.placeholder = "Email"
})

let action = UIAlertAction(title: "Submit",
style: UIAlertActionStyle.Default,
handler: {[weak self]
(paramAction:UIAlertAction!) in
if let textFields = alertController?.textFields{
let theTextFields = textFields as [UITextField]
let enteredText:UITextField = theTextFields[0]
print("prompted email: \(enteredText.text)")
// Validate email address
self!.validateEmailAddress(enteredText)
print("Returned from validateEmailAddress()");
// Continue to validate verification code against email address
self!.validateVerificationCodeAgainstEmail()
print("Returned from validateVerificationCodeAgainstEmail()");
}
})

alertController?.addAction(action)

let cancelItem = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController?.addAction(cancelItem)

self.presentViewController(alertController!,
animated: true,
completion: nil)

}
<小时/>
WARNING MESSAGE:
Warning: Attempt to present <UIAlertController: 0x7fe6f0eb4bb0>
on <XXXXXV1.ViewController: 0x7fe6f0cd7400> which is already presenting
<UIAlertController: 0x7fe6f0e3ea50>

最佳答案

如果您执意要一个接一个地显示两个警报,那么您可以在第一个警报显示后将第二个警报延迟一定的时间:

let delay = 10.0 * Double(NSEC_PER_SEC);
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay));
dispatch_after(time, dispatch_get_main_queue(), {
//display the second alert here
})

或者您可以在提交出现错误后关闭警报 Controller 。因此,您可以显示第一个警报,并在按下提交按钮后调用关闭第一个警报:

firstAlert.dismissViewControllerAnimated(true, completion: nil)

完成后,只需按照当前流程即可

关于ios - 验证失败后提示用户再次通过 UIAlertController 输入内容会在日志上显示警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34325563/

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