ios - UICollectionViewUpdateItem 操作 - 在 iOS6 上删除 Collection View 中的项目时无法识别的选择器

标签 ios objective-c ios7 ios6 uicollectionview

我在 iOS6 上发现了一个奇怪的错误。

我正在使用 Collection View 来表示我的应用程序的“树结构”。每个单元格里面都有一个 TableView ,当我在 TableView 中选择一个单元格时,我会用另一个 TableView 推送一个新的 Collection View 单元格。

当在“树根”中选择一个 TableView 单元格时,我需要清除其他 Collection View 单元格,并显示新的。我这样做是这样的:

for(id e in oldData)
{
    if(i < indexPath.row)
    {
        [newData addObject:e];
    }
    else
    {
        [indexPaths addObject:[NSIndexPath indexPathForItem:i inSection:indexPath.section]];
    }
    i++;
}
self.tree = newData;

[self.collectionView deleteItemsAtIndexPaths:indexPaths];

这在 iOS7 中表现出色。然而,在 iOS6 中,我有时得到这个异常:

'NSInvalidArgumentException', reason: '-[UICollectionViewUpdateItem action]: unrecognized selector sent to instance 0xa3eedd0'

这个异常发生在行上

[self.collectionView deleteItemsAtIndexPaths:indexPaths];

我发现了一些关于这个特定问题的线索,但它似乎与 iOS6 上的键盘外观有关。

如何在 iOS6 上找到解决此错误的方法?

谢谢。

编辑:

我认为问题的原因是这样的。检查我的新问题: Subclassing UICollectionViewFlowLayout sometimes crashes on iOS6

最佳答案

引用Docs 请确保以下事项:

  1. indexPaths 参数不能为 nil。 (您还应该检查 indexPaths 没有任何在您当前的 Collection View 中不存在的索引)
  2. 您已在调用此方法之前更新了数据源。

例如

[indexPaths removeAllObjects];
for(id e in oldData)
    {
    if(i < indexPath.row)
    {
        [newData addObject:e];
    }
    else
    {
        [indexPaths addObject:[NSIndexPath indexPathForItem:i inSection:indexPath.section]];
    }
    i++;
}
self.tree = newData;
if([indexPaths count])
    [self.collectionView deleteItemsAtIndexPaths:indexPaths];

希望这对您有所帮助。

关于ios - UICollectionViewUpdateItem 操作 - 在 iOS6 上删除 Collection View 中的项目时无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22555049/

相关文章:

ios - 如何仅使用Cocos2d旋转横向

objective-c - 在xcode中播放音频

php - 从 iPhone 应用程序 -> PHP -> MySQL 保护用户密码的最佳方法是什么?

ios - 如何堆叠 UICollectionView 部分

ios - 为什么在 swift 中一切都是元组?

ios - 如何使用 Swift 将图像上传到 iOS 中的服务器?

ios7 UIWebView Youtube视频

ios - 如何设置自定义 View 后退按钮

ios - 为什么glReadPixels()在iOS 6.0中的此代码中失败?

iOS 7 AutoLayout 底部屏幕的粘性按钮