【问题标题】:Fast Enumeration through UICollectionView Cells - Swift通过 UICollectionView 单元快速枚举 - Swift
【发布时间】:2014-09-04 09:58:34
【问题描述】:

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

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

    // Do Stuff
}

第一行出现以下错误:

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

我尝试过使用可选选项,并且在 Xcode 6 Beta 6 中可以使用,但在“Beta 7”中无济于事

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

【问题讨论】:

    标签: ios swift uicollectionview uicollectionviewcell fast-enumeration


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2015-08-06
      • 2020-05-19
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多