大佬教程收集整理的这篇文章主要介绍了UICollectionViewDataSource cellForItemAt 不在 iOS 14 上运行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在 Xcode 中将构建目标更新为 iOS 14 后,不会调用 cellForItemAt。然而, numberOfItemsInSection 被调用,但 cellForItemAt 没有被调用,这使得它很奇怪。我以前从未见过这个。
知道它可能是什么吗?
extension LogintableCell: UICollectionVIEwDelegate,UICollectionVIEwDatasource {
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,numberOfItemsInSection section: int) -> Int {
return self.cells.count
}
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: IndexPath) -> UICollectionVIEwCell {
let cell = collectionVIEw.dequeueReusableCell(withReusEIDentifIEr: "LoginCollectionCell",return cell
}
我看不到您设置单元格大小的任何位置,因此请确保您的单元格内容大小设置正确。如果您使用的是流布局,您可以像这样设置大小:
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.itemSize = CGSize(width: 50,height: 50)
collectionView.collectionViewLayout = layout
或者,您可以使用 UICollectionViewDelegateFlowLayout 协议返回单元格的大小:
extension LoginTableCell: UICollectionViewDelegate,UICollectionViewDatasource,UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: int) -> Int {
return self.cells.count
}
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReusEIDentifier: "LoginCollectionCell",return cell
}
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 100,height: 100)
}
以上是大佬教程为你收集整理的UICollectionViewDataSource cellForItemAt 不在 iOS 14 上运行全部内容,希望文章能够帮你解决UICollectionViewDataSource cellForItemAt 不在 iOS 14 上运行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。