6

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()
            }
         }
    }
Francis F
  • 3,157
  • 3
  • 41
  • 79

3 Answers3

17

Replace: UIApplication.shared.beginIgnoringInteractionEvents() ->>> self.view.isUserInteractionEnabled = false

and

UIApplication.shared.endIgnoringInteractionEvents() ->>> self.view.isUserInteractionEnabled = true

slfan
  • 8,950
  • 115
  • 65
  • 78
Eloy
  • 171
  • 1
  • 5
0

begin/end IgnoringInteractionEvents is now deprecated in iOS 13.0, use UIView's userInteractionEnabled property instead on your "myIndicatorView". And make your "myIndicatorView full screen so it covers the whole screen, that will allow you to block the whole app while it is visible.

StackUnderflow
  • 2,403
  • 2
  • 21
  • 28
  • But how? We already see this warning message in Xcode. Would you mind posting the code which makes it happen? – zeeshan Jun 21 '20 at 21:26
0

IgnoringInteractionEvents is now deprecated in iOS 13.0 so You must use isUserInteractionEnabled

    DispatchQueue.main.async {
                appdelegate.myIndicatorView?.removeFromSuperview()
                appdelegate.myIndicatorView = nil
               //you must use this
               self.view.isUserInteractionEnabled = false
//This is deprecated in iOS13
//             UIApplication.shared.endIgnoringInteractionEvents()
            }
Hideyasu.T
  • 809
  • 6
  • 5