【发布时间】:2018-03-26 09:58:30
【问题描述】:
将 UICollectionView 作为 UITableView 行的子项。 UICollectionView 包含图像,但是每当我向下和向上滚动 tableview 时,集合视图图像就会随机消失。我附上图片以供我的问题参考。请建议我如何阻止这种情况。
我希望我的 tableview 是这样的。并且它的项目不应该在滚动时改变。
------------------------------------------ -------------------------------------------------- ------------------------------------------------强>
collectionview 图像在滚动 tableview 时消失。向上滚动后是这样的。
代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell:PartOfLookTableViewCell = self.looksListTable.dequeueReusableCell(withIdentifier: "cell") as! PartOfLookTableViewCell
let oneRecord = looksArray[indexPath.row]
cell.myCollectionView.loadInitial(_dataArray: oneRecord.imagesArray, isLooks: 1)
return cell
}
将数据加载到 CollectionView 的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: looksReuseIdentifier, for: indexPath) as! CustomCollectionViewCell
let oneRecord = inputArray[indexPath.row]
cell.productImage.sd_setImage(with: URL.init(string: oneRecord.thumb_url)){ (image, error, cacheType, url) in
DispatchQueue.main.async {
cell.productImage.image = image
}
}
}
}
}
【问题讨论】:
-
请添加您的代码
-
UITableViewCells 被重复使用,因此您需要在 CellForRowAtIndexPath 方法中设置图像
-
您可以为图像应用标签并基于标签从服务器下载图像。
-
对不起,我忘了添加代码。问题已编辑...
-
@Morti:感谢您的建议。粗体格式不是我做的。
标签: ios swift uitableview uicollectionview