我在 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 请确保以下事项:
indexPaths
参数不能为nil
。 (您还应该检查indexPaths
没有任何在您当前的 Collection View 中不存在的索引)- 您已在调用此方法之前更新了数据源。
例如
[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/