2012-03-24 170 views
2

我有一个应用程序中的几个UITableViews和刷卡删除工作正常所有人。问题是,当我尝试扫过空单元格(底部),应用程序只是崩溃与:滑动时滑动删除

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1914.84/UITableView.m:833 
2012-03-24 16:20:03.158 [22339:707] Exception - attempt to delete row 3 from section 0 which only contains 3 rows before the update - attempt to delete row 3 from section 0 which only contains 3 rows before the update 

无论cellForRowAtIndexPath, commitEditingStyle也不editingStyleForRowAtIndexPath在飞机坠毁前被调用时,它就像在飞机坠毁前的任何情况我的方法有机会被调用。

仅供参考,我有这样的editingStyleForRowAtIndexPath

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if ((indexPath.row == self.insertIndex && indexPath.section == [self.sections count] -1) || (indexPath.row == 0 && [sections count]==0)) { // last row of section, or only row of only section 
     return UITableViewCellEditingStyleInsert; 
    } else { 
     return UITableViewCellEditingStyleDelete; 
    } 
} 

UPDATE:这实际上是一个巨大的问题,因为该应用程序时几乎不可用的实现代码如下滚动。

+0

什么代码,你已经在editingStyleForRowAtIndexPath – Darren 2012-03-24 16:35:34

+0

我已经添加了代码,但应用程序崩溃之前。 – Echilon 2012-03-24 17:00:26

+0

如果没有任何方法正在调用,您是否正确设置了委托? – Darren 2012-03-24 17:16:43

回答

11

看起来像这样的根本原因是试图刷新时重新加载表视图中的行。一定有某种不一致的状态导致每次崩溃应用程序。

+0

我刚刚有同样的问题。在我的commitEditingStyle删除代码中,我调用了一个从中央存储对象中删除行的方法。中央存储对象具有通知,该通知在删除上发布以刷新所有使用数据的表视图。我注释掉了[tableView deleteRowsAtIndexPaths:...行并解决了问题。我不知道这是否会在将来导致一些问题,因为现在桌面视图依靠数据存储来发送该通知 – 2013-03-09 23:49:20

+0

我做了另一个更改。以防中央存储对象逻辑发生变化,并且不会将通知发送回tableView。所以我把[tableView deleteRowsAtIndexPaths:...换回来,同时在通知调用处理程序(它只是叫做reloadData)中检查一下,如果表正在编辑,也就是table isEditing = YES,不会重新加载。现在,如果存储对象不发送该通知消息,tableview代码将不会崩溃在不一致的状态 – 2013-03-09 23:56:17

+0

也适用于我的情况下的UICollectionView – Ryan 2014-08-26 11:15:55

0

解决方案:这就是所谓的

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ 
// tableView.isEditing ? NSLog(@"show edit controls"):NSLog(@"don't show edit controls"); 

    if(tableView.isEditing){ 
     return NO; 
    }else{ 
     return YES; 
    } 
}