Когда я удаляю строку из UITableView с помощью commitEditingStyle, мое приложение вылетает со следующим сообщением об ошибке.Странная вещь, хотя я удаляю из раздела 3. Несоответствие в соответствии с сообщением из раздела 4.
* Ошибка подтверждения в - [UITableView _endCellAnimationsWithContext:], / SourceCache / UIKit_Sim/UIKit-1262.60.3/UITableView.m:920 2010-11-22 19: 56: 44.789 bCab [23049: 207] * Завершение работы приложения из-за необработанного исключения «NSInternalInconsistencyException», причина: «Неверное обновление: недопустимый номерстрок в разделе 4. Количество строк, содержащихся в существующем разделе после обновления (1), должно быть равно количеству строк, содержащихся в этом разделе до обновления (0), плюс или минус количество вставленных или удаленных строкиз этого раздела (0 вставлено, 0 удалено). '
В источнике данных я обновляю раздел 4 в зависимости от количества строк в разделе 3. Когда строка удаляется из раздела 3, количество строкв разделе 4 идет от 0 до 1. Это, кажется, вызывает проблему.Нет ли способа избежать этого?
Любые указатели будут высоко оценены.Спасибо.
ОБНОВЛЕНИЕ :
numberOfSectionsInTableView - (NSInteger) numberOfSectionsInTableView: (UITableView *) tableView {return 6;
}
numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
bCabAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if (section == 0) { // First name, last name
return 2;
}
else if (section == 1) { // Password
return 2;
}
else if (section == 2) { // Mobile, DOB , Gender
return 3;
}
else if (section == 3) { // credit cards
return [creditCards count];
}
else if (section == 4) { // Add credit card
if ([creditCards count] >= 3) {
return 0;
}
else {
return 1;
}
}
else if (section == 5) {
return 0;
}
return 0;
}
commitEditingStyle
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
if (indexPath.section == 3) {
// Delete the row from the data source
NSLog(@"%d %d", indexPath.section, indexPath.row);
[creditCards removeObjectAtIndex:indexPath.row];
// Delete from backend
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
//[tableView reloadData];
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
Я пытался с и без [tableView reloadData] с одинаковыми результатами.
Спасибо за попытку помочь!