【发布时间】:2018-01-12 12:56:58
【问题描述】:
我有一个集合视图单元格,里面有一个 imageView。在它上面我使用sd_setImage 显示图像数组,一旦从firestore 加载。在控制台中,我看到了我的应用下载的所有图像。
我使用这个代码:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "newDetailCollectionCell", for: indexPath) as! NewDetailCollectionViewCell
cell.imageView.sd_setImage(with: URL(string: images[indexPath.item]))
return cell
}
当我使用此代码时,我看不到我的图像。但是,如果我使用下面的代码,一切正常。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "newDetailCollectionCell", for: indexPath) as! NewDetailCollectionViewCell
cell.imageView.sd_setImage(with: URL(string: images[indexPath.item]))
return cell
}
【问题讨论】:
-
你可以在 numberOfItemsInSection 处设置断点并打印“images.count”吗?
-
请添加整个代码。
-
@VDPurohit 如果我打印
images.count我看到 1 个项目。但我仍然有 tableView 和 tableView 向我展示了 images.count = 10 -
@KeyurHirani 我添加了代码,我认为不需要更多代码来解决问题
-
我在控制台中看到所有图像,但为什么我的图像不想出现?我在 mainstoryboard 中所做的委托和数据源