无法根据其 JSON id 快速更改单元格的愿望清单图像

问题描述

我正在使用以下代码获取选定的心愿单项目的 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 (将#修改为@)