У меня возникли проблемы с добавлением новой строки в мой UITableView. Я читал подобные вопросы о stackoverflow, искал его, ... не помог мне.NSInternalInconsistencyException при добавлении строки в UITableView
У меня есть пустой NSMutableArray * dataForList с данными для UITableView. После щелчка на экране я хочу добавить новую строку. Эта ошибка показывает:
* Нагрузочного приложение из-за неперехваченное исключение «NSInternalInconsistencyException», причина: «попытка вставить строку 0 в раздел 0, но есть только 0 строк в разделе 0 после обновления»
Код:
NSArray *insertIndexPaths = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:
[self.dataForList count] // is zero now
inSection:0]];
[self.dataForList addObject:newRow];
// [self.dataForList count] is 1 now
[self.unsignedTableView beginUpdates];
[self.unsignedTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.unsignedTableView endUpdates]; // on this line error ocours
Что мне не хватает?
методы Все UITableView
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath {}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
return [self.mainController.dataForList count];
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath{
return 38.0f;
}
- (UITableViewCell *) tableView: (UITableView *) tableView
cellForRowAtIndexPath: (NSIndexPath *) indexPath {
// call render method in view, it works fain
return [self.signUpToTestView renderUnsignedCell:tableView cellForRowAtIndexPath:indexPath];
}
Это может быть полезно: http://stackoverflow.com/questions/1470898/using-insert-rows-in-a-uitableview – o15a3d4l11s2
Ваш массив данныхForList, который, как я полагаю, является источником данных для вашего вида таблицы, отсутствует синхронизации с состоянием таблицы. – jmstone617
Да, я тоже так думаю, но я не знаю, где я делаю загадку. – kraag22