我有一个 Venue
类型的数组(4 项),每个数组包含一个 imgURLs
字符串数组(2 项),我得到一个 ERROR:索引在我的 collectionView
cellForItemAt
的以下行超出范围。我正在尝试在 tableview 单元格内的 collectionView 中显示每个 Venue 的图像。
let urlString = filteredVenueArray[collectionView.tag].imgURLs[collectionView.tag]
cellForItemAt
函数:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VenueListingCellImage", for: indexPath) as! VenueListingCellImage
let urlString = filteredVenueArray[collectionView.tag].imgURLs[collectionView.tag]
let imgURL = URL(string: urlString)
cell.configureCell(url: imgURL!)
return cell
}
编辑:numberOfItemsInSection
函数
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return filteredVenueArray[collectionView.tag].imgURLs.count
}
最佳答案
改变这一行
let urlString = filteredVenueArray[collectionView.tag].imgURLs[collectionView.tag]
到
let urlString = filteredVenueArray[collectionView.tag].imgURLs[indexPath.item]
关于ios - tableview 单元格中的 uicollection View 出现错误 : Index out of range, 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50577087/