gpt4 book ai didi

json - 从后台线程修改自动布局引擎

转载 作者:行者123 更新时间:2023-11-30 13:23:07 25 4
gpt4 key购买 nike

由于我创建了 readJson 方法,因此出现此错误:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.
Stack:(
0 CoreFoundation 0x0000000100731d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001024d8deb objc_exception_throw + 48
2 CoreFoundation 0x0000000100731cbd +[NSException raise:format:] + 205
3 Foundation 0x0000000100cadb6b _AssertAutolayoutOnMainThreadOnly + 79
4 Foundation 0x0000000100b0d357 -[NSISEngine withBehaviors:performModifications:] + 31
5 UIKit 0x0000000101850adb -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 58
6 UIKit 0x0000000101850477 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 646
7 UIKit 0x0000000101850ae4 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 67
8 UIKit 0x00000001018501ac -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 242
9 UIKit 0x0000000101005538 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 113
10 UIKit 0x0000000101005461 -[UIView(Hierarchy) _postMovedFromSuperview:] + 544
11 UIKit 0x000000010101326c -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1967
12 MacCRM 0x0000000100471a40 _TFE6MacCRMCSo6UIViewP33_0AB6F1737B613FE8A7F8E017F6C0671E9showToastfT5toastS0_8durationSd8positionPs9AnyObject__T_ + 1296
13 MacCRM 0x000000010046e8bc _TFE6MacCRMCSo6UIView9makeToastfT7messageSS8durationSd8positionPs9AnyObject__T_ + 428
14 MacCRM 0x0000000100471ee3 _TToFE6MacCRMCSo6UIView9makeToastfT7messageSS8durationSd8positionPs9AnyObject__T_ + 99
15 MacCRM 0x000000010046e688 _TFE6MacCRMCSo6UIView9makeToastfT7messageSS_T_ + 136
16 MacCRM 0x000000010046e6f8 _TToFE6MacCRMCSo6UIView9makeToastfT7messageSS_T_ + 72
17 MacCRM 0x000000010049c176 _TFFFC6MacCRM7Ajustes7guardarFPs9AnyObject_T_U_FT_T_U_FTGSqCSo6NSData_GSqCSo13NSURLResponse_GSqCSo7NSError__T_ + 7462
18 MacCRM 0x000000010048c0a7 _TTRXFo_oGSqCSo6NSData_oGSqCSo13NSURLResponse_oGSqCSo7NSError__dT__XFdCb_dGSqS__dGSqS0__dGSqS1___dT__ + 103
19 CFNetwork 0x0000000103a17b49 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
20 CFNetwork 0x0000000103a2a0f2 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 302
21 Foundation 0x0000000100bac630 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
22 Foundation 0x0000000100ae7805 -[NSBlockOperation main] + 101
23 Foundation 0x0000000100aca725 -[__NSOperationInternal _start:] + 646
24 Foundation 0x0000000100aca336 __NSOQSchedule_f + 194
25 libdispatch.dylib 0x0000000102f6e3eb _dispatch_client_callout + 8
26 libdispatch.dylib 0x0000000102f5482c _dispatch_queue_drain + 2215
27 libdispatch.dylib 0x0000000102f53d4d _dispatch_queue_invoke + 601
28 libdispatch.dylib 0x0000000102f56996 _dispatch_root_queue_drain + 1420
29 libdispatch.dylib 0x0000000102f56405 _dispatch_worker_thread3 + 111
30 libsystem_pthread.dylib 0x00000001032c24de _pthread_wqthread + 1129
31 libsystem_pthread.dylib 0x00000001032c0341 start_wqthread + 13

我知道问题是什么,并且阅读查找我必须使用 dispatch_async(dispatch_get_main_queue()) { 我在内部调用我的方法,但仍然存在问题。有什么想法吗?

谢谢

编辑:已解决

问题是我的 toast 库。

最佳答案

您的代码不正确。您正在使用:

dispatch_async(dispatch_get_main_queue()) {...

在启动dataTask之前,dataTask将异步运行,也就是说,由于dataTask将异步工作,所以闭包将在后台线程中执行。

您可以通过删除以下行来修复它:

dispatch_async(dispatch_get_main_queue()) {

从它所在的位置然后将其添加到完成 block 中,如果你有这样的:

...{ data, response, error in
dispatch_async(dispatch_get_main_queue()) {

它会工作得很好。

但是你应该只在计算操作完成时调用主线程,这样困难的部分就由后台线程完成。

关于json - 从后台线程修改自动布局引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37544899/

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