gpt4 book ai didi

ios - 使 uicollectionview 单元出队时出现问题(swift 3)

转载 作者:行者123 更新时间:2023-11-30 12:27:22 25 4
gpt4 key购买 nike

我在将 uicollectionview 中的多个单元格出队时遇到问题。有人可以逐步解释一下从注册到出队的过程吗?我在网上找不到任何有关在一个 Collection View 中加载两个或多个 uicollectionview 单元格的信息。同样,这是为了在基于 coreadata 的变量的单个 Collection View 中加载多种类型的单元格。

这是我到目前为止所拥有的。

这是我注册单元格的地方

    collectionView?.register(ShareCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.register(ShareCellMedia.self, forCellWithReuseIdentifier: mediaCellId)

这是索引路径中项目的单元格

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

let friend = fetchedResultsController.object(at: indexPath) as! Friend
if (friend.lastMessage?.hasImage)! == true {
let mediaCell = collectionView.dequeueReusableCell(withReuseIdentifier: mediaCellId, for: indexPath) as!
ShareCellMedia
mediaCell.cell = friend.lastMessage
return mediaCell

}else{


let regularCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as!
ShareCell
regularCell.cell = friend.lastMessage
return regularCell
}

}

最佳答案

如果您使用原型(prototype)静态单元,则无需注册单元,或者如果您使用带有 xib 的单元,则可以像这样注册

     collectionView.register(UINib(nibName: "name here",bundle:nil), forCellWithReuseIdentifier: "identifier")

并检查或打印您的标识符

关于ios - 使 uicollectionview 单元出队时出现问题(swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44018222/

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