我需要在內核被推入核心數據庫時更新tableview。當核心數據被推入核心數據時,需要立即更新tableview iphone
此 AppDelegate.m包含下面的代碼
NSManagedObjectContext *moc = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"FeedItem" inManagedObjectContext:moc]];
//for loop
// push data in code data & then save context
[moc save:&error];
ZAssert(error == nil, @"Error saving context: %@", [error localizedDescription]);
//for loop ends
此代碼觸發以下從RootviewController.m
- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller
{
[[self tableView] beginUpdates];
}
代碼,但只在for循環結束這個更新的tableview,在數據庫立即推送後,表不會得到更新。
我嘗試下面的代碼,但沒有提前上班
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// In the simplest, most efficient, case, reload the table view.
[self.tableView reloadData];
}
我一直堅持這個問題好days.Please help.Thanks的解決方案。
對不起,但我不明白這部分, //獲取下一個要更新的對象 id object = [stuffToUpdate objectAtIndex:stuffToUpdate.count-1]; [stuffToUpdate removeLastObject]; 在我的情況下的對象是RSS飼料項目和下載的文章。這在AppDelegate.m中被推入核心數據中。但是你寫的代碼將在RootviewController.m中。我應該如何使用第二種方法?請幫助 – user336685 2010-05-12 10:39:43