Fast Enumeration through UICollectionView Cells - Swift

我的未来我决定 提交于 2019-12-07 02:10:26

问题


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:

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

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

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


回答1:


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

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


来源:https://stackoverflow.com/questions/25662520/fast-enumeration-through-uicollectionview-cells-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!