我有这样的结构...
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)
}
}
当我点击集合视图项目上的一个按钮时,我加载了一个tableviewcell,它具有集合视图单元格中的所有细节,如名称,速率等。这样就完成了......
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)
}
但问题是我无法正确传递图像。
同样在加载tableviewcell的viewcontroller中,这就是我在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
}
但是从每个单元格的集合视图显示的图像不合适。换句话说,没有显示每个索引路径的正确图像......
感谢任何帮助......谢谢...... :)