iOS 7 UITableView 问题 - 当我们已经有一个单元格时尝试设置滑动以删除单元格

Posted

技术标签:

【中文标题】iOS 7 UITableView 问题 - 当我们已经有一个单元格时尝试设置滑动以删除单元格【英文标题】:iOS 7 UITableView issue - attempting to set a swipe to delete cell when we already have one 【发布时间】:2014-03-15 15:24:54 【问题描述】:

我发现 ios 7 存在问题。当我将 UITableView 置于编辑模式时 - 我注意到我可以点击多个红色“-”按钮以在多个单元格上显示“删除”选项。发生这种情况时,我在控制台日志中看到以下警告。此外,经过一些操作后,我无法点击“-”按钮。

在 iOS 6 中运行良好。

这是 iOS7 的错误吗?有人知道解决方法吗?

在我们已有单元格的情况下尝试设置滑动删除单元格....这似乎不太好`

- (BOOL)tableView:(UITableView *)iTableView canEditRowAtIndexPath:(NSIndexPath *)iIndexPath 
    return (self.isEditMode) ? YES : NO;



- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)iIndexPath 
    return (iIndexPath.row !=0 && self.isEditMode) ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;

【问题讨论】:

【参考方案1】:

这是 iOS 7 的一个问题,将在下一个 iOS 版本中修复。已将此情况报告给 Apple。

【讨论】:

现在我用的是 Xcode 5.1.1 ,还是有同样的问题【参考方案2】:

我有同样的错误,直到我改变我的方法:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
        //remove the deleted object from your data source.
        //If your data source is an NSMutableArray, do this
        [self.array removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    


我希望这对其他人有帮助。

【讨论】:

支持一个可行的解决方案!谢谢...

以上是关于iOS 7 UITableView 问题 - 当我们已经有一个单元格时尝试设置滑动以删除单元格的主要内容,如果未能解决你的问题,请参考以下文章