내 앱에서 UITableView & 사용자 요청 후 원격으로 테이블 데이터를 업데이트 할 수 있습니다. 내가 코어 데이터 & NSFetchedResultsController를 사용하여 변경이 발생한 경우, -controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
가 호출됩니다 :셀을 업데이트 한 후 UITableView 렌더링이 잘못되었습니다.
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;
case NSFetchedResultsChangeMove:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
모두는 한 가지를 제외하고, 올바르게 작동합니다. 때로는 첫 번째 행을 다시로드 한 후 테두리없이 표시됩니다 (테두리가 갑자기 사라짐). 무엇이 잘못 될 수 있습니까?
추신 : 데이터 업데이트를 위해 백그라운드에서 새로 NSManagedObjectContext
을 생성하고 NSManagedObjectContextDidSaveNotification
을 (를) 관리합니다. 알림이 오면 기본 스레드에서 mergeChangesFromContextDidSaveNotification
이 수행되므로 메인 스레드에서도 업데이트됩니다.
그러나 처음으로 셀이 올바르게 표시되는 이유는 무엇입니까? 코드는 동일합니다 - 레이블 텍스트 만 다릅니다! – kpower
흠. 나는'tableView : cellForRowAtIndexPath :'코드에서 셀의 배경을 생성하는 동안 만 설정하고 다시로드 할 때마다 설정하지 않는 코드를 변경했다. 이제는 모두 잘 동작한다. – kpower