2012-01-09 7 views

답변

0

당신은 이미 컨트롤러에 옵저버가 설정되어있어 가져 오기 요청을 다시 시작해야하는 postNotificaton을 사용할 수 있습니다.

+0

postNotification에서 데이터를 업데이트 다시? –

1

당신이

fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[self managedObjectContext] sectionNameKeyPath:nil cacheName:nil]; 

는 추적 할 수없는 가망하고 무기 호에 매개 변수 cacheName의 값을 설정할 수 있습니다,이 위임 방법을 사용하여. 그것은 충돌 방지와 ManagedObjectContext 변경 후 만 현재 데이터를 유지

#pragma mark - 
#pragma mark Fetched results controller delegate 


- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { 
[self.tableView beginUpdates]; 
} 


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo 
     atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { 

switch(type) { 
    case NSFetchedResultsChangeInsert: 
     [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
     break; 

    case NSFetchedResultsChangeDelete: 
     [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
     break; 
} 
} 


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject 
    atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type 
    newIndexPath:(NSIndexPath *)newIndexPath { 

UITableView *tableViews = self.tableView; 

switch(type) { 

    case NSFetchedResultsChangeInsert: 
     [tableViews insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     break; 

    case NSFetchedResultsChangeDelete: 
     [tableViews deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     break; 

    case NSFetchedResultsChangeUpdate: 
     [_delegate configureCell:[tableViews cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; 
     break; 

    case NSFetchedResultsChangeMove: 
     [tableViews deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     [tableViews insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade]; 
     break; 
} 
} 


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
[self.tableView endUpdates]; 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
[self.tableView scrollToRowAtIndexPath:indexPath 
         atScrollPosition:UITableViewScrollPositionMiddle 
           animated:NO]; 
} 

이 코드를 자동으로 업데이트하고 추가 할 때, 삭제하거나 NSFetchedResultsController하고있는 UITableViewController

+0

변경 수가 적 으면 작동합니다. 대량 업데이트를 얻으면 UI 스레드가 끔찍하게 지연 될 것입니다 ... – jjxtra

+0

저는 1조차도 문제가 있습니다.하지만 지연이 아닙니다. –

관련 문제