首页 > 解决方案 > 如何在 UITableViewCell 中使用 UICollectionView 显示场地列表的图像?

问题描述

我有一个UICollectionView在一个UIIMageViewUICollectionViewCell

UICollectionViewa 中,UITableViewCell我想显示.VenueUITableViewCell

这是我的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 图像?

标签: iosswiftuitableviewuicollectionview

解决方案


在这里,我为您提供场景,如何在UICollectionView内部实现VenueListingCell

首先,在您的创建中,您应该在自定义类中创建您的Venue对象。VenueListingCell

现在你有了venue每个 indexPath 的对象VenueListingCell

awakeFromNib(),设置你的

collectionView.delegate = self 
collectionView.dataSource = self

VenueListingCell自定义类中,

实现自定义类中datasource的所有delegate方法。UICollectionViewVenueListingCell

如有任何疑问,请告诉我。


推荐阅读