【发布时间】:2018-12-30 12:05:43
【问题描述】:
我尝试实现有关产品的详细视图。我将 tableview 用于产品详细信息,并决定在 tableview 标题中为产品图像创建一个 collectionview。我创建了一个包含集合视图和 2 个标签的 Xib 文件。我将这个 Xib 实现为 tableview 标题。我可以重新加载表格视图行,但我没有在标题中重新加载集合视图。
如何重新加载此收藏视图?
我在提取 json 后使用此代码,它允许我在 tableview 单元格中显示参数。
let sectionIndex = IndexSet(integer: 0)
self.tableView.reloadSections(sectionIndex, with: .none)
在 viewDidLoad() 中
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
}
提前致谢。
【问题讨论】:
标签: ios swift xcode uitableview xib