【发布时间】:2017-08-29 07:45:36
【问题描述】:
我遇到了一个问题,UICollectionView 中显示的数据覆盖了标签,并且单元格视图没有被清除。
这张图片显示了问题,
IE:
我的 UICollectionViewCell 是这样构造的;
// in viewDidLoad
self.playerHUDCollectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier:reuseIdentifer)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifer, for: indexPath) as UICollectionViewCell
let arr = UINib(nibName: "EYPlayerHUDView", bundle: nil).instantiate(withOwner: nil, options: nil)
let view = arr[0] as! EYPlayerHUDView
cell.contentView.addSubview(view)
if let allPlayers = self.allPlayers
{
let player:EYPlayer = allPlayers[indexPath.row]
view.updatePlayerHUD(player: player)
}
cell.layoutIfNeeded()
return cell
}
我使用视图在单元格中显示。
我尝试删除cellForItemAt 中的所有单元格子子项,但它似乎删除了所有子视图。
我想知道如何清除UICollectionViewCell,以便UICollectionViewCell 上的标签和其他信息不会像上面的示例那样脏。
非常感谢
【问题讨论】:
-
您的回答有帮助。虽然代码在 Objective C 中;我能够根据我的要求修改和更新它!
-
在您的自定义单元格类中覆盖 prepareForResure 方法并添加所需的清理。
-
但是没有自定义单元格类。考虑;集合视图单元格是空的,除了添加子视图之外什么都不做。
标签: ios swift uicollectionviewcell reload