IOS 不在主线程操作UI
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread, this can lead to engine corruption and weird crashes.
在子线程中操作UI相关的操作了;
修改方式,将操作UI的代码块(注意代码块里不能有return)放到如下宏定义里
1 2 3 4 5 6 7 8 | #ifndef dispatch_main_async_safe #define dispatch_main_async_safe(block)\ if (dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL) == dispatch_queue_get_label(dispatch_get_main_queue())) {\ block();\ } else {\ dispatch_async(dispatch_get_main_queue(), block);\ } #endif |
//主线程同步队列 https://blog.csdn.net/qq_26341621/article/details/50156157 #define dispatch_main_sync_safe(block)\ if ([NSThread isMainThread]) {\ block();\ } else {\ dispatch_sync(dispatch_get_main_queue(), block);\ } //主线程异步队列 #define dispatch_main_async_safe(block)\ if ([NSThread isMainThread]) {\ block();\ } else {\ dispatch_async(dispatch_get_main_queue(), block);\ } //用法 dispatch_main_async_safe(^{ //需要执行的代码片段; });
如果你放到代码块中的代码有return操作,就会报错:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-05-18 Linux 声音采集的时候内容全都是0