swift - UICollectionView 上的可见单元不能在没有参数的情况下调用

标签 swift uicollectionview

文档在这里:https://developer.apple.com/documentation/uikit/uicollectionview/1618056-visiblecells

但我似乎不能使用这个: notesCollectionView.visibleCells() 作为! [NotesCollectionViewCell]

有一个错误: “不能不带参数调用‘visibleCells’”

如何只获取 UICollectionView 中的 visibleCells?

最佳答案

visibleCells 是一个变量,但您使用的是函数调用语法。 删除 () 应该可以解决问题。

if let cells = notesCollectionView.visibleCells as? [NotesCollectionViewCell]
{
    // Do your magic here.
}

关于swift - UICollectionView 上的可见单元不能在没有参数的情况下调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56848665/

相关文章:

ios - GKTurnBasedMatchmaker 是如何使用的?

arrays - (自己回答)Swift 数组在函数 numberofRows 中返回 0 个计数(在 tableView 中,但在其他任何地方它返回正确数量的 array.count

ios - 删除包含标题等于 tableView textLabel 的注释

带有自定义 View Controller 的 iOS 共享扩展

ios - 标签未出现在 UICollectionView 单元格上方

ios - 在我的 tableView 中滚动时如何隐藏 collectionView (知道这个 ViewCOntroller 是一半 tableview 和一半 collectionview )

ios - Swift 1.2 中未正确实现随机播放功能

ios - Collection View - 从不同文件夹接收图像 - 如何?

ios - 关于 Swift 中 collectionView 单元格内的 UIButton 行为的问题

ios - 如何检查一次 UserDefaults 是否为空