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

Ios 如何在UITableViewCell中使用UICollectionView显示场馆列表的图像?,ios,swift,uitableview,uicollectionview,Ios,Swift,Uitableview,Uicollectionview,我有一个UICollectionView,在UICollectionView单元格中有一个UIIMageView UICollectionView位于UITableViewCell中,我想在UITableViewCell中显示特定场馆的所有图像(保存在URL字符串数组旋转木马样式中) 这是我的tableViewcellForRowAt,它完美地显示了场馆 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexP

我有一个
UICollectionView
,在
UICollectionView单元格中有一个
UIIMageView

UICollectionView
位于
UITableViewCell
中,我想在
UITableViewCell
中显示特定
场馆的所有图像(保存在URL字符串数组旋转木马样式中)

这是我的
tableView
cellForRowAt
,它完美地显示了
场馆

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中使用正确的场馆图像?

这里我向您提供了一个场景,如何在
VenueListingCell
内部实现
UICollectionView

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

现在,您有了
VenueListingCell
的每个indexath的
venue
对象

awakeFromNib()
中,设置

collectionView.delegate = self 
collectionView.dataSource = self
VenueListingCell
自定义类中

VenueListingCell
自定义类中实现
UICollectionView
的所有
datasource
delegate
方法


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

您的CollectionView cellForItemAt在UITableView Cell中,对吗?正确。需要明确的是,我的数据集由一个类型为Venue(FilteredvenuArray)的数组组成,每个Venue都包含一个类型为String(imgURLs)的数组,我希望以旋转木马的方式为每个场地加载该数组。为什么要使用venueLoaded?这就是我遇到的问题,我想我会把场地从牢房保存到venueLoaded中,这样我就可以用它去imgURLs显示图像,但它不起作用。解决方案完成了吗?