insertRowsAtIndexPaths :에 문제가 있습니다. 어떻게 작동하는지 잘 모르겠습니다. WWDC 2010 비디오를 보았지만 여전히 오류가 발생합니다. 나는 모델을 업데이트하기로되어 있다고 생각하고 insertRowsAtIndexPaths를 래핑했다. tableView beginUpdates와 endUpdates 호출에서. 내가 가지고있는 것은 :insertRowsAtIndexPaths가있는 테이블 뷰 업데이트가 잘못되었습니다.
self.customTableArray = (NSMutableArray *)sortedArray;
[_customTableView beginUpdates];
[tempUnsortedArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[sortedArray enumerateObjectsUsingBlock:^(id sortedObj, NSUInteger sortedIdx, BOOL *sortedStop) {
if ([obj isEqualToString:sortedObj]) {
NSIndexPath *newRow = [NSIndexPath indexPathForRow:sortedIdx inSection:0];
[_customTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newRow] withRowAnimation:UITableViewRowAnimationAutomatic];
*sortedStop = YES;
}
}];
}];
[_customTableView endUpdates];
customTableArray는 내 모델 배열입니다. sortedArray는 해당 배열의 정렬 된 버전입니다. 더하기 버튼을 눌러 새 행을 추가 할 때이 코드를 실행하면이 오류가 발생합니다.
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 (2) 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 (2 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
내가 잘못하고있는 것이 확실하지 않습니다. 생각? 감사.