gpt4 book ai didi

ios - 返回默认的 UICollectionViewCell 缺少 reuseIdentifier

转载 作者:行者123 更新时间:2023-11-28 13:28:27 28 4
gpt4 key购买 nike

如果我尝试返回默认的 UICollectionViewCell 应用程序崩溃,因为它缺少 reuseIdentifier:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the cell returned from -collectionView:cellForItemAtIndexPath: does not have a reuseIdentifier - cells must be retrieved by calling -dequeueReusableCellWithReuseIdentifier:forIndexPath:'

代码:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

return UICollectionViewCell()
}

使用 UITableViewCells 它工作得很好。 UICollectionViews 中默认返回的最佳做法是什么?

最佳答案

对我有用的是:

collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "default")

然后:

return collectionView.dequeueReusableCell(withReuseIdentifier: "default", for: indexPath)

作为默认返回。但我希望有更清洁的东西。

关于ios - 返回默认的 UICollectionViewCell 缺少 reuseIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57907314/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com