0
嗨,大家好,我收到這個錯誤,當我嘗試添加到一個空表視圖:插入行0到部分0,但更新後0節只有0行。有什麼想法嗎?表視圖插入錯誤
dispatch_queue_t fetchQ = dispatch_queue_create("Blog Fetcher", NULL);
dispatch_async(fetchQ, ^{
//pull this call out to Blog+twitter later saving should only take
//place in the model!
[document.managedObjectContext performBlock:^
{
NSArray* resultsArray = [self.tweets objectForKey:@"results"];
for (NSDictionary* internalDict in resultsArray)
{
User *user = [NSEntityDescription
insertNewObjectForEntityForName:@"User"inManagedObjectContext:self.context];
user.username =[internalDict objectForKey:@"from_user_name"];
[self.context save:nil];
self.list = [self.list arrayByAddingObject:user];
NSLog(@" indexpath set here %i",self.list.count-1);
NSIndexPath *newIndexpath =[NSIndexPath indexPathForRow:self.list.count-1 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}];
});
dispatch_release(fetchQ);
}
正如@JefferyThomas所暗示的,UIKit對象(例如tableview)的所有更新都必須從主線程完成。另外,確保所有的核心數據保存都在同一個線程上完成(不要在主線程**和**這個線程上執行)。 – lnafziger