This application is modifying the autolayout engine from a background thread
来源:互联网 发布:成都php 编辑:程序博客网 时间:2024/05/22 07:02
我在用NSURLSession做请求:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://XXX"]];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *sessionDataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *_Nullable data,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:nil];
[self.tableView reloadData];
}];
[sessionDataTask resume];
报错如下:
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:(......)
结论:
1、在子线程中是不能进行UI 更新的,而可以更新的结果只是一个幻像:因为子线程代码执行完毕了,又自动进入到了主线程,执行了子线程中的UI更新的函数栈,这中间的时间非常的短,就让大家误以为分线程可以更新UI。如果子线程一直在运行,则子线程中的UI更新的函数栈 主线程无法获知,即无法更新
2、只有极少数的UI能,因为开辟线程时会获取当前环境,如点击某个按钮,这个按钮响应的方法是开辟一个子线程,在子线程中对该按钮进行UI 更新是能及时的,如换标题,换背景图,但这没有任何意义
将上述方法改为:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@
"http://XXX"
]];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *sessionDataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[myTableView reloadData];
});
}];
[sessionDataTask resume];
0 0
- This application is modifying the autolayout engine from a background thread after the engine was ac
- iOS9 This application is modifying the autolayout engine from a background thread, which
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- iOS9 This application is modifying the autolayout engine from a background thread, which
- iOS 错误信息 This application is modifying the autolayout engine from a background thread...
- This application is modifying the autolayout engine from a background thread...
- 崩溃问题:iOS9 This application is modifying the autolayout engine from a background thread, which
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- "This application is modifying the autolayout engine from a background thread, which can lead to en
- This application is modifying the autolayout engine from a background thread 原因
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- This application is modifying the autolayout engine from a background thread
- This application is modifying the autolayout engine from a background thread, which can lead t
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- warning:This application is modifying the autolayout engine from a background thread
- This application is modifying the autolayout engine from a background thread, which can lead to engi
- 安卓 数据库操作详解
- CentOS6.6安装ShadowSocks服务端
- 点击按钮改变本身按钮的文字内容
- 学习
- Eclipse javax.comm.NoSuchPortException
- This application is modifying the autolayout engine from a background thread
- manven项目Java Resource红叉报错的处理
- SQLServer——字符长度
- 理解inode
- LeetCode Reverse Vowels of a String(字符串中元音字符反转)
- IntelliJ IDEA 16 本地LicenseServer激活(破解)
- JS查看Object对象的内容
- C#控制台 输出hello world
- mysql进阶:group_concat使用例子