我的UITableViewController或NSFetchedResultsController有点问题.我不确定问题是什么,但我猜它是UITableViewController.
正如我所说的,我使用NSFetchedResultsController将我的数据填充到UITableViewController中.数据按日期排序,并按日期显示在各个部分,例如2010年5月/ 2010年6月/等.这显示为节标题.
现在,当我添加新数据时,它会自动使用当前日期作为默认值,但是如果我想使用日期,那当前不在部分列表中,例如2010年4月(目前列表中的5月和6月),那么这是没有正确显示.只有当我退出应用程序并再次启动它时,它才会显示新的部分标题,一切都很好.
所以我需要能够刷新我的列表或更新它.只需将其添加到上下文并更改它似乎不会更新它.
同样,我不知道我需要更新什么,如果它是我的NSFetchedResultsController对象或UITableViewController.
更新#1:
我只想到这个方法有一个例外:
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
// The fetch controller has sent all current change notifications, so tell the table view to process all updates.
[self.tableView endUpdates];
}
Run Code Online (Sandbox Code Playgroud)
这是我移动数据的地方:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
UITableView *tableView = self.tableView;
switch(type)
{
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
// [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
// …Run Code Online (Sandbox Code Playgroud)