gpt4 book ai didi

ios - UIAlertController 错误在 swift 模式呈现的 View Controller 中调用时

转载 作者:可可西里 更新时间:2023-11-01 01:39:12 26 4
gpt4 key购买 nike

我有一个以模态方式呈现的 View Controller ,当我运行 UIAlertController 时,不断收到错误消息。我该如何解决这个问题。

警报由检查文本字段是否为空的按钮触发。

@IBAction func registerAction(sender: AnyObject) {
if(userEmail.isEmpty){
alertMessage("Fields Are Empty")
}
}



func alertMessage(userMessage:String){
var myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
}

当我运行警报时出错

Warning: Attempt to present <UIAlertController: 0x7f9bbb9060d0>  on <AlertApp.CustomSignupVC: 0x7f9bb94accb0> which is already presenting <UIAlertController: 0x7f9bbb926660>

最佳答案

尝试将其添加到主操作队列中。

dispatch_async(dispatch_get_main_queue()) {
self.presentViewController(myAlert, animated: true, completion: nil)
}

检查这个相关问题:Presenting a view controller modally from an action sheet's delegate in iOS8 - iOS10

关于ios - UIAlertController 错误在 swift 模式呈现的 View Controller 中调用时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32111569/

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