У меня было приложение, которое работает в iOS6, но когда я обновил iOS7 с тем же кодом, с которым я работал, я получаю эту ошибку, когда пытаюсь удалить строку в таблица:Ошибка при удалении строки в UITableView (только в iOS7)
2013-10-02 17:44:11.344 Goal[1877:a0b] *** Assertion failure in -[UITableView
_endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:1330
2013-10-02 17:44:11.384 Goal[1877:a0b] *** 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 (1) must be equal to the number of rows contained in that section
before the update (1), plus or minus the number of rows inserted or
deleted from that section (0 inserted, 1 deleted) and plus or
minus the number of rows moved into or out of that section
(0 moved in, 0 moved out).'
вот некоторые методы, если вам это нужно
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
// deleting
NSManagedObjectContext *moc = self.managedObjectContext;
Goal *goalToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
[moc deleteObject:goalToDelete];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
еще один
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"GoalCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.backgroundColor = [UIColor clearColor];
Goal *goal = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = goal.title;
return cell;
}
и нет, я не Бесполезный забудьте проверить свой идентификатор соты,
Если у вас есть более продвинутая реализация UITableViewSource, где у вас есть переменная, свойство или метод, отслеживающий количество строк (в разделе при использовании разделов), Мехмет прав, что вам нужно будет убедиться, что количество строк уменьшается. Перед вызовом deleteRowsAtIndexPath количество строк должно быть уменьшено на количество удаленных строк. Спасибо, Мехмет! – Miros