저는 UITableViews
을 제어하기 위해 Matt Gallagher의 GenericTableViewController
아이디어를 사용하고 있습니다. 내 데이터 소스는 NSFetchedResultsController
입니다. 내가 셀을 삭제하려고 할 때까지어떻게 deleteRowsAtIndexPaths를 만들 수 있습니까? GenericTableViewController와 함께 작동합니까?
http://cocoawithlove.com/2008/12/heterogeneous-cells-in.html
모든 것이 잘 작동한다.
내보기 컨트롤러에 다음 코드를 가지고 :
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object.
NSManagedObjectContext *context = [wineryController managedObjectContext];
[context deleteObject:[wineryController objectAtIndexPath:indexPath]];
NSError *error;
if (![context save:&error]) {
// Handle the error.
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
마지막 줄은 콘솔의 다소 자세한 설명과 함께 충돌 :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
확인, 나는 무슨 말을 이해합니다. .. 행이 삭제되지 않습니다. (나는 정상적인 위치에서 코드를 옮겼으므로) 올바른 위치로 메시지를 전달하지 않기 때문에 행성이 추측됩니다. 누군가는 어떤 생각을 가지고 있습니까? 나는 이걸 완전히 뒤죽박죽이다.
+1 답변을 많이 보내 주셔서 감사합니다. –
애니메이션 블록보다 먼저 데이터 소스를 수정할 수 있습니다. 본 오류는 삭제를 애니메이션으로 만들기 전에 데이터 소스를 변경하지 않았 음을 나타냅니다. 해당 행의 제거에 애니메이션을 적용하기 전에 데이터 소스가 삭제 이후 최종 상태인지 확인하십시오. – Mark
나는 항상 이것을 잊어 버렸습니다 ... XCode 템플릿 코드에 왜이 줄이 포함되어 있지 않습니까? – Echelon