gpt4 book ai didi

ios - 警报不会解除(警告 : Attempt to dismiss from view controller. ..)

转载 作者:行者123 更新时间:2023-11-28 07:23:11 24 4
gpt4 key购买 nike

所以我有一个功能,当 Alamofire 正在做一些事情时显示警报,我想在 Alamofire 完成后关闭警报,但有时它有效,有时它不!当它不起作用时,我收到错误消息(iOS 13、Xcode 11 Beta 5):警告:在演示或关闭过程中尝试从 View Controller (UITabBarController:0x7f90b7013a00)关闭!

这是我用来显示警报的函数:

func showLoadingDialog(show : Bool)  {
let alert = UIAlertController(title: nil, message: "⏳ Please wait...", preferredStyle: .alert)
if show == true {


let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
loadingIndicator.hidesWhenStopped = true
loadingIndicator.style = .medium
loadingIndicator.startAnimating()
alert.view.addSubview(loadingIndicator)
present(alert, animated: true, completion: nil)
} else {
dismiss(animated: true, completion: nil)
// I've tried the "alert.dismiss" but it doesn't work!
//alert.dismiss(animated: true, completion: nil)
alert.removeFromParent()
}
}

此外,我正在使用标签栏,在其中一个标签栏内,我正在使用导航 Controller ,在其中我有一个表格 View ,因此当用户单击单元格时,它会转到另一个 View Controller (在同一个 Storyboard内)文件)使用此代码:

let detailsVC = storyboard?.instantiateViewController(identifier: "Bdetails") as? DetailsController
self.navigationController?.pushViewController(detailsVC!, animated: true)

然后我还禁用了导航栏(我猜是标题,我正在使用自定义按钮返回预览页面,使用此代码:

self.navigationController?.popViewController(animated: true)

这里还有 Alamofire,我在其中放置了警报功能,我在 viewDidLoad 中使用它:

func libHttp(url: String) {

// Showing the alert.
showLoadingDialog(show: true)
Alamofire.request(url).responseJSON { (responseData) ->
Void in
if ((responseData.result.value) != nil) {

let libJSON = JSON(responseData.result.value!)
if let libData = libJSON.array {
for detail in libData {
// putting the values into an object from a custom class
}

// Updates the storyboard elements' value with the objects values.
self.update()

// dismissing the alert.
self.showLoadingDialog(show: false)
}
}
}
}

最佳答案

当您调用 libHttp(url:) 函数时,这似乎是一个竞争条件。从导航 Controller 中弹出 viewController 后,检查是否存在解除警报的情况。

关于ios - 警报不会解除(警告 : Attempt to dismiss from view controller. ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57409305/

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