这是一个创建于 3823 天前的主题,其中的信息可能已经有所发展或是发生改变。
我在使用 AFNetworking 库(1.x),然后在异步刷新时候,在
[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
...
[self.jsonData addObjectsFromArray:JSON[@"objects"]];
dispatch_async(dispatch_get_main_queue(), ^{
[self.titleLabel setFrame:CGRectMake(60, 5, 100, 40)];
[self.tableView reloadData];
});
...
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
...
}];
上面主要是在获得数据后,在主线程更新 UI(reloadData)。然后发现*有时候*,会出现 EXC_BAD_ACCESS,查看 crash report 显示是 [self.titleLabel setFrame:CGRectMake(60, 5, 100, 40)]; 这一行。
请问这样写是有什么问题么?
5 条回复 • 2014-05-13 09:16:30 +08:00
|
|
1
dorentus 2014-05-03 16:55:01 +08:00 via iPhone 1
non-ARC?
self.titleLabel 是什么,可能是它的问题吧
|
|
|
2
INT21H 2014-05-03 18:00:27 +08:00
@ dorentus ARC self.titleLabel 是自定义的一个 label,但是 setFrame 在主线程中操作也不会有问题吧?
|
|
|
3
alexrezit 2014-05-03 18:18:32 +08:00 via iPhone 1
__weak
|
|
|
4
cielpy 2014-05-03 18:37:44 +08:00 1
没记错的话[@"objects"]这咱写法是6.0才有的吧,那为什么不用AF 2.x版本呢。 block回调有对象的循环引用问题,这个我现在也没太搞明白,LS提到__weak应该是指这个问题吧 看看那个label setFrame的时候还在不在,然后数组有没有越界?
|
|
|
5
R0CKSTAR 2014-05-13 09:16:30 +08:00
Diagnostics里面把Enable Zombie Objects打开,看log就能知道是哪个对象野了
|