如何在UITableViewCell中使用UICollectionView显示场地列表的图像?

时间:2018-05-29 03:54:52

标签: ios swift uitableview uicollectionview

我在UICollectionView内有一个UIIMageView UICollectionViewCell

UICollectionViewUITableViewCell范围内,我想显示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图像?

1 个答案:

答案 0 :(得分:0)

在此,我将为您提供方案,如何在UICollectionView内实施VenueListingCell

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

现在,venue的每个indexPath都有VenueListingCell个对象。

awakeFromNib()中,设置

collectionView.delegate = self 
collectionView.dataSource = self

VenueListingCell自定义类

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

如有任何疑问,请与我联系。