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