Я использую код ниже, чтобы обновить табличное представление, в которое я только что добавил строку. Код работает для добавления строки в таблицу, если в таблице уже есть хотя бы 1 строка. Однако происходит сбой, если изначально это была пустая таблица.
NSArray *indexPaths = [NSArray arrayWithObjects: [NSIndexPath indexPathForRow:[commentsArray count] inSection:0], nil];
[commentsTableView beginUpdates];
[commentsArray addObject:newestEntry];
[commentsTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
[commentsTableView endUpdates];
[commentsTableView scrollToBottom:YES];
Ответ на сбой, который я получаю:
*** 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 (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'
Может ли кто-нибудь мне помочь?