1
我基本上试图重新加载UITableView数据时使用块数据以非阻塞的方式加载回来。使用块来重新加载UITableView数据崩溃
[query findObjectsInBackgroundWithBlock:^(NSArray * objects, NSError * error){
if (!error){
for (PFObject * vote in objects){
if([vote objectForKey:@"note"]){
NSString * username = ((PFUser *)[vote objectForKey:@"voter"]).username;
NSLog(@"Username is %@", username);
[self.notes addObject:[NSDictionary dictionaryWithObject:[vote objectForKey:@"note"] forKey:username]];
NSLog(@"Note is %@", [vote objectForKey:@"note"]);
}
}
[self.tableView reloadData];
}
//[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
}];
的问题是,下面的代码将产生一个错误:
bool _WebTryThreadLock(bool), 0x246d20: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
这是我的cellForRowAtIndexPath里面:
这是为什么?如何解决这个问题?
所以只是把该块里面? – aherlambang
是的,用我提出的代码替换你的代码行[self.tableView reloadData];'。 – DarkDust
另外,您需要使用锁来防止对'self.notes'的并发访问(除非它已经是线程安全的容器)。 – DarkDust