【发布时间】:2017-07-24 07:44:31
【问题描述】:
我在我的 api 调用机制中使用了一个活动指示器,在隐藏 HUD 时代码崩溃并出现“[UIActivityIndicatorView release]: message sent to deallocated instance”的错误。
这里是堆栈:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x18a5e6ea8)
* frame #0: 0x000000018a5e6ea8 CoreFoundation`___forwarding___ + 744
frame #1: 0x000000018a4e2d4c CoreFoundation`_CF_forwarding_prep_0 + 92
frame #2: 0x000000018a4c2a80 CoreFoundation`-[__NSArrayI dealloc] + 84
frame #3: 0x0000000189062134 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 836
frame #4: 0x0000000190711c3c UIKit`-[UIView dealloc] + 1604
frame #5: 0x0000000189062134 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 836
frame #6: 0x000000018a4beb28 CoreFoundation`_CFAutoreleasePoolPop + 28
frame #7: 0x000000018a58ecec CoreFoundation`__CFRunLoopRun + 1580
frame #8: 0x000000018a4beda4 CoreFoundation`CFRunLoopRunSpecific + 424
frame #9: 0x000000018bf28074 GraphicsServices`GSEventRunModal + 100
frame #10: 0x0000000190779058 UIKit`UIApplicationMain + 208
frame #11: 0x0000000100147448 GraspIO-Dev`main at AppDelegate.swift:14
frame #12: 0x00000001894cd59c libdyld.dylib`start + 4
我不明白我在犯什么错误,这是我的显示和隐藏代码。
func execute( _ params : String..., serverResponse: @escaping (ServerResponseModel) -> Void) {
//print("params:\(params)");
if self.mCallingView != nil {
DispatchQueue.main.async{
self.showLoadingHUD()
}
}
}
makeWebServiceCall(params){
response in
//print("\n\n response: \(response)")
DispatchQueue.main.async {
serverResponse(response!)
if self.mCallingView != nil {
self.hideLoadingHUD()
}
}
}
}
fileprivate func showLoadingHUD() {
let hud = MBProgressHUD.showAdded(to: mCallingView!, animated: true)
hud.label.text = "Please wait..."
}
fileprivate func hideLoadingHUD() {
let _ = MBProgressHUD.hide(for: mCallingView!, animated: true)
mCallingView!.isUserInteractionEnabled = true
mCallingView = nil
}
隐藏HUD时应用会崩溃,研究了堆栈溢出,但找不到解决方案。
【问题讨论】:
-
是“makeWebServiceCall”这个类的属性作为强参考吗?如果是这样 - 你需要添加 [weak self] 到它
-
弱引用@GrzegorzKrukowski
-
你能把你所有的属性贴出来吗?标签是什么样子的,进度条是什么样子的?
-
在 swift 中试用这个适用于 iOS 的 HUD 库 github.com/shubh10/JustHUD
标签: swift memory-management uiactivityindicatorview dealloc mbprogresshud