이전에 discussed here처럼 두 NSFetchedResultsControllers (두 섹션이있는 테이블, 각 NSFetchedResultsControllers에 대해 하나의 섹션)의 결과로 구동되는 UITableView로 UITableViewController를 구현했습니다.UITableView는 두 개의 NSFetchedResultsController가 공통 결과로 구동합니다.
두 코드 모두 NSFetchedResultsController가 공통으로 사용하지 않으면 내 코드가 올바르게 실행되고 오류없이 실행됩니다.
Serious application error. An exception was caught from the delegate of
NSFetchedResultsController during a call to -controllerDidChangeContent:.
Invalid update: invalid number of rows in section 0. The number of rows contained in
an existing section after the update (1) must be equal to the number of rows contained
in that section before the update (1), plus or minus the number of rows inserted or
deleted from that section (1 inserted, 0 deleted). with userInfo (null)
I가 요청하고 있습니다 때마다 내가 출력 해요 : 내 NSFetchedResultsControllers의 모두에서 결과로 보여 코어 데이터 개체를 삽입 할 때
, 나는이 문제로 실행 해요
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo;
if (section < [self.fetchedResultsController1.sections count]) {
sectionInfo = [[self.fetchedResultsController1 sections] objectAtIndex:section];
}
else {
sectionInfo = [[self.fetchedResultsController2 sections] objectAtIndex:section-[self.fetchedResultsController1.sections count]];
}
NSLog(@"Section %d with %d row(s)", section, [sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
및 개체 didObject 삽입 도착마다 프린트 아웃 : 섹션의 행 번호
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
NSLog(@"Inserting %@ %@", newIndexPath, anObject);
[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];
// Reloading the section inserts a new row and ensures that titles are updated appropriately.
[tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
,745 I 위의 코드를 실행할 때 1,515,
, I는 상기 오차 (명료 함) 다음과 같은 결과를 얻을 즉시이를 따르
2012-03-28 00:59:55.611 MyApp[517:207] Section 1 with 0 row(s)
2012-03-28 00:59:55.612 MyApp[517:207] Section 0 with 0 row(s)
2012-03-28 00:59:55.613 MyApp[517:207] Inserting <NSIndexPath 0x5948150> 2 indexes [0, 0] <MyClass: 0xd60f8b0> (entity: MyClass; id: 0xd611d50 <x-coredata:///MyClass/tD7E0DB3C-4D85-468C-9DD0-BAD0A53B20A310> ; data: {
....
})
2012-03-28 00:59:55.614 MyApp[517:207] Section 0 with 1 row(s)
2012-03-28 00:59:55.614 MyApp[517:207] Section 1 with 0 row(s)
2012-03-28 00:59:55.618 MyApp[517:207] Inserting <NSIndexPath 0x5948150> 2 indexes [0, 0] <MyClass: 0xd60f8b0> (entity: MyClass; id: 0xd611d50 <x-coredata:///MyClass/tD7E0DB3C-4D85-468C-9DD0-BAD0A53B20A310> ; data: {
....
})
2012-03-28 00:59:55.619 MyApp[517:207] Section 0 with 1 row(s)
2012-03-28 00:59:55.620 MyApp[517:207] Section 1 with 1 row(s)
2012-03-28 00:59:55.620 MyApp[517:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995
2012-03-28 00:59:55.621 MyApp[517:207] Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted). with userInfo (null)
는 그 결과 중복 될 단일 jQuery과 구동 두 NSFetchedResultsControllers를 갖는 아니 좋은 생각? 그것은 받아 들일 수있는 대답이지만 가능한 경우이 오류를 피하기 위해 무엇을 할 수 있습니까?
내 NSFetchedResultsControllerDelegate 메소드는'[tableView beginUpdates]'와'[tableView endUpdates]'를 호출합니다. 그리고 이것은 또한 사실입니다 : tableView는 섹션의 수와 각 섹션의 행 수를 먼저'endUpdates'를 호출하십시오. 나는 첫 번째 접근법의 수정 된 버전을 따를 것이다. 내 섹션에서 두 가지 다른 정렬 순서가 필요하기 때문에 여전히 두 개의 'NSFetchedResultController's가 필요하다고 생각하지만 두 개의 다른 섹션에서 같은 개체를 사용하지 않아도됩니다. –