gpt4 book ai didi

ios - 在 UICollectionViewCell iOS Swift 4 中注册 header 时出错

转载 作者:行者123 更新时间:2023-11-30 11:53:30 26 4
gpt4 key购买 nike

我正在做让我们构建那个应用程序的 Twitter 重制教程,我不断遇到这个错误:“无法使某种 View 出队:带有标识符 headerId 的 UICollectionElementKindSectionFooter - 必须为标识符注册一个 Nib 或一个类,或者连接一个原型(prototype) Storyboard中的单元格'。我尝试注册下面的标题,但我的应用程序仍然给我同样的错误。这是视频的链接: https://www.youtube.com/watch?v=2fcf9yFe944&list=PL0dzCUj1L5JE1wErjzEyVqlvx92VN3DL5

let cellId = "cellId"
let headerId = "headerId"

override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = .white
collectionView?.register(WordCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.register(UICollectionViewCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerId)
}

最佳答案

您将该 View 注册为 UICollectionElementKindSectionHeader,但尝试将其用作 UICollectionElementKindSectionFooter。这些细节是关键。

您可以通过执行以下操作来检查以确保 collectionView 方法获取正确的类型:

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionElementKindSectionHeader {
//Now you can dequeue your view with reuseId "headerId"
} else {
//This is where you set the footerView, if you are using one
}

关于ios - 在 UICollectionViewCell iOS Swift 4 中注册 header 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48086369/

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