У меня есть пользовательский UITableView
Я пытаюсь добавить строку в tableView
. Вот мой код:Добавление строки в таблицуView не работает
- (IBAction)addRow:(id)sender
{
NSInteger indexPath = [self.rowArray count] - 1;
// I'm adding an object to an array of all the cell ids I have.
[self.rowArray insertObject:@"rowSix" atIndex:indexPath]; // rowSix is a cell ID
[self.myTableView beginUpdates];
[self.myTableView endUpdates];
}
Это ошибка, что он выводит:
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 (8) must be equal to the number of rows contained in that section before the update (7), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Update
В cellForRowAtIndexPath
:
NSString *cellID = [self.rowArray objectAtIndex:[indexPath row]];
customCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
Если у вас есть массив сотовых идентификаторов, вы, вероятно, делать что-то не так. У вас обычно есть только один идентификатор для каждого типа ячейки. У вас есть несколько типов ячеек (разные подклассы)? – rdelmar
использовать [self.myTableView reloadData]; вместо '[self.myTableView beginUpdates]; [self.myTableView endUpdates]; ' –
@rdelmar У меня разные прототипы ячеек. –