为自定义的UICollectionviewCell实现countbyenumerating状态 [英] Implementing countbyenumeratingwithstate for custom UICollectionviewCell

查看:232
本文介绍了为自定义的UICollectionviewCell实现countbyenumerating状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我添加了一个select all / deselect all按钮,这显然应该会影响所有的细胞在我的collectionView。为了做到这一点,我打算使用这样的for循环:

pre $ for(customCollectionViewCell * cell in self.collectionView){
//一些代码
}

然而我首先得到一个警告: / b>

 集合表达式类型UICollectionView *许多不对应于countByEnumeratingWithStage:objects:count
$ b

当我编译程序并单击按钮时,应用程序崩溃,出现以下错误消息:

$ pre $ 终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:' - [UICollectionView countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例0x7973e00'

有没有人有关于如何解决这个问题的想法?

非常感谢您的帮助!

解决方案

不要迭代集合视图本身,而是迭代cel ls通过调用 visibleCells 方法返回。


I am building an app with a CollectionView filled with custom CollectionViewCell.

I added a button "select all/deselect all" which is obviously supposed to affect all the cell in my collectionView. To do this I intended to use a for-loop like this:

for(customCollectionViewCell* cell in self.collectionView){  
    // some code
}

However i first get a warning saying:

Collection expression type "UICollectionView *" many not correspond to "countByEnumeratingWithStage:objects:count"

And when I compile the program and click on the button, the app crash with the following error message:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionView countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7973e00'

Does anyone have an idea on how to solve this?

Many thanks for your help!

解决方案

Don't iterate the collection view itself, but rather the array of cells it returns by calling the visibleCells method on it.

这篇关于为自定义的UICollectionviewCell实现countbyenumerating状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆