У меня есть следующие примеры кода:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[namesArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
и
if ([nameSection count] == 0)
{
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView beginUpdates];
[indexKeys removeObjectAtIndex:section];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
Обратите внимание на порядок.... в первом примере я сначала удаляю объект из своего массива, а затем удаляю строку из таблицы.
Во втором примере я удаляю строку из таблицы, затем раздел из моего массива, затем раздел из таблицы.
Это правильный порядок действий? Или я должен сначала удалить его из пользовательского интерфейса, а затем массивы?
Причина, по которой я спрашиваю, заключается в том, что некоторые пользователи сообщают об этих сбоях, которые я не могу воспроизвести:
NSInternalInconsistencyException — недопустимое обновление: недопустимое количество строк в разделе 1. Количество строк, содержащихся в существующем разделе после обновления (0), должно быть равно количеству строк, содержащихся в этом разделе до
с этой трассировкой стека:
1: libobjc.A.dylib objc_exception_throw 32
2: CoreFoundation [NSException raise:format:] 0
3: Foundation -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 90
4: UIKit -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] 6042
5: UIKit -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] 254
6: UIKit -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] 26
7: Movies _mh_execute_header 253319
8: UIKit -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] 84
9: CoreFoundation -[NSObject performSelector:withObject:withObject:] 52
10: UIKit -[UIApplication sendAction:to:from:forEvent:] 62