ios - tableview 单元格中的 uicollection View 出现错误 : Index out of range, 为什么?

标签 ios swift uicollectionview

我有一个 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/

相关文章:

ios - 在 HStack 中以正确的方式对齐两个 SwiftUI TextView

iphone - IAP 完成时隐藏/取消隐藏 IBOutlet(UIButton)

ios - 我在 iPad 应用程序中实现 Oracle UCM 是否有任何用于登录身份验证的 Web 服务?

swift - 在 cellForItemAtIndexPath 之外访问 CollectionViewCell 属性

ios - 如何获取相机胶卷中所有视频文件的url?

ios - 是否可以在 UITabBarController 中显示 SFSafariViewController?

ios - 将 swift 文件移动到现代框架但失去了 Flurry Analytics 功能

ios - 如何快速切换到最后一页上的不同 View Controller ?

ios - UICollectionView 和 UITableView 重新加载会导致单元格重新排序

ios - UICollectionView 加载速度太慢