So I have a function that shows an alert while Alamofire is doing some stuff and I want to dismiss the alert when Alamofire is done but sometimes it works and sometimes it doesn't! and when it doesn't work I'm getting the error (iOS 13, Xcode 11 Beta 5): Warning: Attempt to dismiss from view controller (UITabBarController: 0x7f90b7013a00) while a presentation or dismiss is in progress!
This is the function I use to show the alert:
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()
}
}
Also I'm using tab bars and inside one of the tab bars I'm using the navigation controller and inside that I've a tableview so when the user clicks the cells it goes to another view controller (inside the same storyboard file) using this code:
let detailsVC = storyboard?.instantiateViewController(identifier: "Bdetails") as? DetailsController
self.navigationController?.pushViewController(detailsVC!, animated: true)
and then I've also disabled the navigation bar (the header I guess and I'm using a custom button to return to the previews page using this code:
self.navigationController?.popViewController(animated: true)
also here is the Alamofire where I've put the alert function and I'm using it inside 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)
}
}
}
}