My scenario, I am trying to create Loader within AlertViewController
. Here, I am getting below warnings and not allowing to dismiss after two trials. I am using below function in a common class and reusing in multiple viewController.
My Code
// MARK: Common AlertView
extension UIViewController {
func loadinHubShow() {
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
loadingIndicator.hidesWhenStopped = true
loadingIndicator.style = UIActivityIndicatorView.Style.gray
loadingIndicator.startAnimating();
alert.view.addSubview(loadingIndicator)
present(alert, animated: true, completion: nil)
}
func loadinHubDismiss() {
dismiss(animated: false, completion: nil)
}
}
Other ViewController
func dataJson() {
// Start Loading
self.loadinHubShow()
// after process done
DispatchQueue.main.async {
self.loadinHubDismiss()
}
}
My Warning
Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!