我在UICollectionView
内有一个UIIMageView
UICollectionViewCell
。
UICollectionView
在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图像?
答案 0 :(得分:0)
在此,我将为您提供方案,如何在UICollectionView
内实施VenueListingCell
。
首先,在您的创建中,您应该在Venue
自定义类中创建VenueListingCell
对象。
现在,venue
的每个indexPath都有VenueListingCell
个对象。
在awakeFromNib()
中,设置
collectionView.delegate = self
collectionView.dataSource = self
在VenueListingCell
自定义类
在datasource
自定义类中实施delegate
的所有UICollectionView
和VenueListingCell
方法。
如有任何疑问,请与我联系。