我尝试实现有关产品的详细视图。我使用tableview查看产品详细信息,并决定在tableview标题中为产品图像创建collectionview。我创建了一个包含一个集合视图和两个标签的Xib文件。我实现了这个从Xib到tableview的标题。我可以重新加载tableview行,但我没有在标题中重新加载collectionview。
如何重新加载此collectionview?
我在提取json后使用了这段代码,它允许我在tableview单元格中显示参数。
let sectionIndex = IndexSet(integer: 0)
self.tableView.reloadSections(sectionIndex, with: .none)
if element.result.productImages?.count ?? 0 > 0 {
for x in element.result.productImages! {
print(x)
self.productImages.append(x.imageUrl)
self.productDetailHeaderView.productImagesCollectionView.reloadData()
}
}
在CellForRowAt
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductImagesCollectionViewCell", for: indexPath) as! ProductImagesCollectionViewCell
cell.productImage.sd_setImage(with: URL(string: "\(productImages[indexPath.row])"), placeholderImage: UIImage(named: "placeholder"))
return cell
}
--
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let v : ProductDetailHeaderView = UIView.fromNib()
productDetailHeaderView = v
productDetailHeaderView.translatesAutoresizingMaskIntoConstraints = false
productDetailHeaderView. productImagesCollectionView.register(UINib(nibName: "ProductImagesCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ProductImagesCollectionViewCell")
productDetailHeaderView.backgroundColor = .yellow
return productDetailHeaderView
}
提前谢谢。