A progress warning that does not deviate from viewing in Swift 3

I am trying to create a function to show and reject the ProgressDialog in Swift 3. But in this code the dialog does not deviate from the view controller.

func showLoadingDialog(show : Bool) { if show { self.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.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray loadingIndicator.startAnimating() self.alert.view.addSubview(loadingIndicator) self.present(self.alert, animated: true, completion: nil) }else{ self.dismiss(animated: false, completion: nil) } } 

I also tried the following methods to reject this dialog, but none of them worked:

 self.alert.view.removeFromSuperview() self.alert.view.alpha = 0 self.presentingViewController?.dismiss(animated: true, completion: nil) 

Please help me. If you have an alternative solution, make an offer.

+5
source share
2 answers

//Try it

 func showLoadingDialog(show : Bool) { if show { if self.alert == nil{ self.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.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray loadingIndicator.startAnimating() self.alert.view.addSubview(loadingIndicator) } if !self.alert.isBeingPresented { self.present(self.alert, animated: true, completion: nil) } }else{ self.alert.dismiss(animated: false, completion: nil) } } 
+4
source

In func showLoadingDialog ,

try using

self.alert.dismiss(animated: false, completion: nil)

instead

self.dismiss(animated: false, completion: nil)

+3
source

Source: https://habr.com/ru/post/1270412/


All Articles