gpt4 book ai didi

swift - [UIActivityIndi​​catorView发布] : message sent to deallocated instance in swift-3

转载 作者:行者123 更新时间:2023-11-30 12:17:09 26 4
gpt4 key购买 nike

我在我的 api 调用机制中使用事件指示器,在隐藏 HUD 时,代码会崩溃并发出“[UIActivityIndi​​catorView release]:消息发送到已释放实例”的错误

这是堆栈:

 * 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 时会崩溃,对堆栈溢出进行了研究,但找不到解决方案。

最佳答案

该错误非常具有描述性。您正在尝试将已经发布的内容设置为零。现在你需要找到你做这件事的地方以及避免这种情况的方法。正如您提到的,您在隐藏它的同时得到了它。所以你已经把注意力集中在这个问题上了。

fileprivate func hideLoadingHUD() {
let _ = MBProgressHUD.hide(for: mCallingView!, animated: true)
mCallingView!.isUserInteractionEnabled = true
mCallingView = nil
}

这里。您正在尝试使mCallingView = nil。删除此行并检查是否出现错误。您真的需要使源 View 为零,同时隐藏事件指示器吗?

关于swift - [UIActivityIndi​​catorView发布] : message sent to deallocated instance in swift-3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45274869/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com