ios - 如何在 UITableViewCell 中使用 UICollectionView 显示场地列表的图像?
问题描述
我有一个UICollectionView
在一个UIIMageView
内UICollectionViewCell
。
在UICollectionView
a 中,UITableViewCell
我想显示.Venue
UITableViewCell
这是我的tableView
cellForRowAt
,它显示得Venues
非常好。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "VenueListingCell", for: indexPath) as? VenueListingCell else { return UITableViewCell() }
let venueCurrent = filteredVenueArray[indexPath.row]
venueLoaded = venueCurrent //copy into var to be used in collectionView
cell.configureCell(venue: venueCurrent)
cell.selectionStyle = .none
return cell
}
这是我的CollectionView
cellForItemAt
功能。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VenueListingCellImage", for: indexPath) as! VenueListingCellImage
let imgURL = URL(string: (venueLoaded?.imgURLs[indexPath.row])!)
cell.configureCell(url: imgURL!)
return cell
}
问题:
如何确保在 UICollectionView 中使用正确的 Venue 图像?
解决方案
在这里,我为您提供场景,如何在UICollectionView
内部实现VenueListingCell
。
首先,在您的创建中,您应该在自定义类中创建您的Venue
对象。VenueListingCell
现在你有了venue
每个 indexPath 的对象VenueListingCell
。
中awakeFromNib()
,设置你的
collectionView.delegate = self
collectionView.dataSource = self
在VenueListingCell
自定义类中,
实现自定义类中datasource
的所有delegate
方法。UICollectionView
VenueListingCell
如有任何疑问,请告诉我。
推荐阅读
- vb.net - 更新不是 tableadapter 的成员
- java - 需要知道我是否可以使用 jmeter 对语音优先反应本机应用程序进行负载\性能测试
- javascript - vue拖放后拖动的项目消失
- jquery - 如何将偏移量应用于另一个页面上的#link
- xcode - 不能做 xcodebuild - 方案有一个空间
- orbeon - 使用自动完成的新组件
- scala - 如何让 Intellij 在 ammonite 脚本中解析私有 maven 存储库中的包?
- javascript - 两个按钮触发一个脚本
- laravel - 不同用户 Laravel 的身份验证(尝试获取非对象的属性)
- intellij-idea - 如何使用 IntelliJ 的结构替换“所有匹配项,除了...”?