Ich habe Probleme mit insertRowsAtIndexPaths :. Ich bin mir nicht sicher, wie es funktioniert. Ich habe das Video der WWDC 2010 darauf gesehen, aber ich bekomme immer noch einen Fehler. Ich dachte, dass ich das Modell aktualisieren sollte, dann wickle die insertRowsAtIndexPaths: in den TableView beginUpdates und endUpdates-Aufrufe. Was ich habe ist das:Ungültige Tabellenansicht mit insertRowsAtIndexPaths aktualisieren:
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 ist mein Modell-Array. sortedArray ist nur die sortierte Version dieses Arrays. Wenn ich diesen Code ausführen, wenn ich meine Plus-Taste schlug eine neue Zeile hinzufügen, bekomme ich diesen Fehler:
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).'
Ich bin nicht sicher, was ich falsch mache. Gedanken? Vielen Dank.