通过 UICollectionView 单元格快速枚举 - Swift [英] Fast Enumeration through UICollectionView Cells - Swift

查看:34
本文介绍了通过 UICollectionView 单元格快速枚举 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试快速枚举我所有的集合视图单元格,但是下面的这个实现给了我一个警告.

I am trying to fast enumerate through all of my collection view cells, however this implementation below is giving me a warning.

for cell in self.collectionView?.visibleCells() as [UICollectionViewCell] {

    // Do Stuff
}

下面的错误出现在第一行:

Error below appears on first line:

后缀'?'的操作数应该有可选类型;类型是'(UICollectionView, cellForItemAtIndexPath: NSIndexPath) ->UICollectionViewCell'

Operand of postfix '?' should have optional type; type is '(UICollectionView, cellForItemAtIndexPath: NSIndexPath) -> UICollectionViewCell'

我尝试过使用可选项并在 Xcode 6 Beta 6 中使用它,但在Beta 7"中无济于事

I've tried messing around with optionals and had this working in Xcode 6 Beta 6, but to no avail in "Beta 7"

我如何摆脱这个错误?/编写一个遍历我所有 CollectionView 单元格的循环?

How do i get rid of this error? / Write a loop that goes through all my CollectionView Cells ?

推荐答案

collectionView 属性现在是一个可选 UICollectionView?,所以你有打开它:

The collectionView property is now an optional UICollectionView?, so you have to unwrap it:

for cell in self.collectionView!.visibleCells() as [UICollectionViewCell] { ... }

这篇关于通过 UICollectionView 单元格快速枚举 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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