gpt4 book ai didi

swift - 如何更新 UIViewController 上的 Collectionview 自定义单元格属性

转载 作者:行者123 更新时间:2023-11-30 10:35:48 27 4
gpt4 key购买 nike

我的自定义单元格具有图像属性。

class AODCameraCollectionViewCell: UICollectionViewCell, NibReusable {

@IBOutlet weak var lblCount: UILabel!
@IBOutlet weak var imgAddCamera: UIImageView!
@IBOutlet weak var viewMain: AODView!
@IBOutlet weak var imgBattery: UIImageView!
@IBOutlet weak var imgWifi: UIImageView!

在我的 View Controller 上

@IBOutlet weak var viewCameraCollection: UICollectionView!
...
//Setup camera collection
viewCameraCollection.register(cellType: AODCameraCollectionViewCell.self)
viewCameraCollection.delegate = self
viewCameraCollection.dataSource = self

在 CollectionView 数据源上我有这个

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: AODCameraCollectionViewCell = collectionView.dequeueReusableCell(for: indexPath)
cell.lblCount.isHidden = true
let c = viewModel.cameras[indexPath.row]

if viewModel.currentMode == .multi {
Logger.i("Showing for index: \(indexPath.row)")
if cell.player == nil, let l = c.link {
let player = playVideo(inView: cell.viewMain, withURL: l)
viewModel.setMediaPlayer(forKey: c.id, withPlayer: player)
cell.player = player
cell.viewType = .preview
} else if c.feedFromPhone {
cell.viewType = .phoneCamera
let feed = AODCameraFeedView(frame: .zero)
feed.delegate = self
viewCameraFeed = feed
cell.viewMain.addSubview(feed)
feed.snp.makeConstraints { (maker) in
maker.edges.equalToSuperview()
}
} else if c.link == nil && !c.feedFromPhone{
cell.viewType = .empty
}
}


return cell
}

有没有办法可以访问我的自定义单元格图像属性,更改它,然后更新单元格而不添加新单元格?

最佳答案

您好,只需根据您的要求重新加载 Collection View 即可。

例如:-

 @objc func reloadCollectionViewAction(sender: UIButton!) {

DispatchQueue.main.async {
self. viewCameraCollection.reloadData()
}

}

关于swift - 如何更新 UIViewController 上的 Collectionview 自定义单元格属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58063003/

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