【发布时间】:2020-01-16 13:09:55
【问题描述】:
我在 ViewController willAppear 方法中进行 API 调用,直到 API 响应完成,我正在使用这个 showWait 和 hideWait 方法来显示和关闭活动指示器。但是我遇到的问题是,在我的 ViewController 中,我有一个带有不同自定义单元格的表格视图,假设我在加载过程中不断点击单元格,一旦加载消失,它的所有操作都会被多次调用。下面是我显示和隐藏指示器的代码,我尝试将 userInteractionEnabled 设置为 false,但没有奏效。此外,尝试了 beginIgnoringInteractionEvents,它在一定程度上有效,但如果你继续点击直到加载器消失,这也会失败。不知道如何从这里开始。任何帮助表示赞赏。
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()
}
}
}
【问题讨论】:
标签: ios touch-event uiactivityindicatorview swift4.2 xcode10.1