我的应用程序在 iOS6 中运行良好,但是当我使用与我正在使用的相同代码更新 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;
}
不,我没有忘记检查我的手机标识符,