如果我尝试返回默认值,UICollectionViewCell应用程序会崩溃,因为它缺少reuseIdentifier:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“从 -collectionView:cellForItemAtIndexPath: 返回的单元格没有重用标识符 - 必须通过调用 -dequeueReusableCellWithReuseIdentifier:forIndexPath: 来检索单元格”
代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return UICollectionViewCell()
}
Run Code Online (Sandbox Code Playgroud)
它UITableViewCells工作得很好。违约退货的最佳实践是什么UICollectionViews?
对我有用的是:
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "default")
Run Code Online (Sandbox Code Playgroud)
进而:
return collectionView.dequeueReusableCell(withReuseIdentifier: "default", for: indexPath)
Run Code Online (Sandbox Code Playgroud)
作为默认返回。但我希望有更干净的东西。
| 归档时间: |
|
| 查看次数: |
3930 次 |
| 最近记录: |