Issue with adding the collection view image to an

2019-07-29 06:10发布

问题:

I'm having a struct like so...

struct ProductImage {
   let id : String
   let url : URL
   let isDefault : Bool
}

struct Product {
    let name : String
    let id : String
    var images = [ProductImage]()
    var theRate : String
    var quantity: String
    var sku: String
    var prdCateg: String
    var prodDescr: String

    init(name : String, id: String, theRate: String, quantity: String, sku: String, prdCateg:String, prodDescr: String) {
        self.name = name
        self.id = id
        self.theRate = theRate
        self.quantity = quantity
        self.sku = sku
        self.prdCateg = prdCateg
        self.prodDescr = prodDescr

    }

    mutating func add(image: ProductImage) {
        images.append(image)
    }
}

And when I click on a button on an item of the collectionview, I load a tableviewcell which has all the details present in the collection view cell like name, rate etc.This is done like so...

 func SellBtnTapped(_ sender: UIButton) {

     let indexPath = collectionView?.indexPath(for: ((sender.superview?.superview) as! RecipeCollectionViewCell))

     self.photoThumbnail = self.arrayOfURLImages[(indexPath?.row)!]

     let myVC = storyboard?.instantiateViewController(withIdentifier: "productSellIdentifier") as! sellTableViewController

     let productObject = productData1[(indexPath?.row)!]
      if selectedItems == nil {

          selectedItems = [Product(name:productObject.name, id: productObject.id, theRate: productObject.theRate, quantity: productObject.quantity, sku: productObject.sku, prdCateg: productObject.prdCateg, prodDescr: productObject.prodDescr)]

     } else {
           selectedItems?.append(productObject)
     }

     myVC.arrProduct = selectedItems
     navigationController?.pushViewController(myVC, animated: true) 
}

But the issue is I'm not able to pass the image properly.

Also in the viewcontroller from where the tableviewcell is loaded, this is how I am assigning the data in the cellForRowAt…

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let cell: sellTableViewCell = tableView.dequeueReusableCell(withIdentifier: "sellProductIdentifier") as! sellTableViewCell

   cell.prdImgView?.image = self.appDelegate.commonArrayForURLImages[indexPath.row]

   let product = arrProduct?[indexPath.row]
   cell.produvtNameLabel.text = product?.name
   cell.rateTextField.text = product?.theRate
   cell.remStockLabel.text = product?.quantity
   return cell
}

But the image displayed from the collectionview on each cell is not proper. In other words, the correct image from each indexpath is not shown...

Any help is appreciated...Thanks..:)