I'm making an API call in my ViewController willAppear method and till the API response completes I'm using this showWait and hideWait method to show and dismiss the activity indicator. But the problem I have is, in my ViewController I have a table view with different custom cells and suppose I keep tapping on the cells during the loading all of its action is getting called multiple times once the loading disappears. Below is my code for showing and hiding indicator, I tried setting userInteractionEnabled to false but that didn't work. Also, tried the beginIgnoringInteractionEvents, it works to some extents but if you keep on tapping till the loader disappears this fails as well. Not sure how to proceed from here. Any help is appreciated.
class func showWait() {
DispatchQueue.main.async {
UIApplication.shared.beginIgnoringInteractionEvents()
if let appdelegate = UIApplication.shared.delegate as? AppDelegate,
appdelegate.myIndicatorView == nil {
appdelegate.myIndicatorView = MyIndicatorView(frame: UIScreen.main.bounds)
appdelegate.window?.subviews[0].addSubview(appdelegate.myIndicatorView!)
}
}
}
class func hideWait() {
if let appdelegate = UIApplication.shared.delegate as? AppDelegate,
appdelegate.myIndicatorView != nil {
DispatchQueue.main.async {
appdelegate.myIndicatorView?.removeFromSuperview()
appdelegate.myIndicatorView = nil
UIApplication.shared.endIgnoringInteractionEvents()
}
}
}
Replace: UIApplication.shared.beginIgnoringInteractionEvents()
->>> self.view.isUserInteractionEnabled = false
and
UIApplication.shared.endIgnoringInteractionEvents()
->>> self.view.isUserInteractionEnabled = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With