我正在尝试使用 AsyncDisplayKit 将图像加载到我的应用程序中。我正在将我的集合视图创建为 ASCollectionView,就像在 viewDidLoad 中一样:
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 90, height: 90)
let collection = ASCollectionView(frame: view.frame, collectionViewLayout: layout)
collection.asyncDataSource = self
collection.asyncDelegate = self
collection.registerClass(cell1.self, forCellWithReuseIdentifier: "cell1")
self.view.layer.addSublayer(collection.layer)
这是我的 nodeForItemAtIndexPath:
func collectionView(collectionView: ASCollectionView, nodeForItemAtIndexPath indexPath:
NSIndexPath) -> ASCellNode {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell1",
forIndexPath: indexPath) as! cell1
return cell
}
nodeForItemAtindexPath 是 cellForItemAtIndexPath 的 AsyncDisplayKit 版本。它必须与 ASCollectionView 一起使用。
问题是“collecitonView.dequeueRreusableCellWithReuseIdentifier”方法返回一个 UICollecitonViewCell。我的单元不是那个,它是一个 ASCellNode。所以我收到一个错误:“从 UICollectionViewCell 转换为不相关的类型 ASNodeCell 总是失败”。
我也在这一行得到一个错误:
collection.registerClass(cell1.self, forCellWithReuseIdentifier: "cell1")
错误提示“尝试注册一个不是 UICollectionViewCell 子类的单元类”。
有没有其他方法可以解决这个问题?我几乎在所有地方都进行了搜索,但是在 Swift(或 obj c 中)中关于 asyncdisplaykit 的可用资源非常少,而且我找不到使用 ASCollectionView 的单个示例项目。任何帮助,将不胜感激。