如何解决无法根据其 JSON id 快速更改单元格的愿望清单图像
@IBAction func addToWishList(_ sender: UIButton){
WishListVC.addToFav(id: self.homDB?.result?.product?.featured_product?[sender.tag].id?.description ?? "",vc: self,handler: {isAdded in
isAdded ? self.serviceCall() : ()
})
idFav = self.homDB?.result?.product?.featured_product?[sender.tag].id
print("favItem id \(idFav)")
}
对于单元格中的 favImage.. 我已经设置了初始 favRemove
图像..
并根据 idFav
更改图像,如下所示
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SliderCollectionCell",for: indexPath) as! SliderCollectionCell
let indexData = featuredData?[indexPath.item]
cell.btnAddToFav.tag = indexPath.item
cell.lblTitle.text = indexData?.product_by_language?.title
cell.lbRealPrice.text = indexData?.discount_price != "0.000" && compareDate(fromDate: indexData?.from_date ?? "",toDate: indexData?.to_date ?? "") ? "\(indexData?.price ?? "") KWD" : ""
cell.favImage.image = idFav != nil ? favAdd : favRemove //<<< here
return cell
}
如果我点击 addToWishList
按钮,那么我需要将 favAdd
图像添加到单元格,如果我再次点击它必须更改 favRemove
图像
但上面的代码最初所有单元格都显示 favRemove
图像..再次没有变化它保持相同的图像
如果我添加到心愿单并从心愿单中删除,如何更改 addToWishList
的图片,请帮忙提供代码。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。