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显示图像,但它不起作用。解决方案完成了吗?