我有像這樣一個結構..問題與添加到陣列而將數據傳遞到另一個視圖
struct Product {
let name : String
let id : String
}
}
我也有稱爲圖像的單獨的陣列arrayOfURLImages
現在我具有collectionview
並且每個collectionview
的單元具有來自arrayOfURLImages
的圖像以及顯示id
和rate
的2個標籤。當我點擊collectionview
的一個項目時,我加載了一個tableviewcell,其上有collectionview
的圖像,還有id
和name
。
在點擊的CollectionView這是我如何傳遞image
和name
& id
...
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: 「mydentifier") as! myViewController
myVC.myImage = self.photoThumbnail
let productObject = productData1[(indexPath?.row)!]
myVC.prodName = productObject.name <— ‘name’ from struct
myVC.prodId = productObject.id <— ‘id’ from struct
navigationController?.pushViewController(myVC, animated: true)
}
現在我的問題是,我想補充這樣加載到一個數組的tableviewcells。此外,在從tableviewcell被加載在視圖 - 控制,這是怎麼了分配在cellForRowAt
數據...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: sellTableViewCell = tableView.dequeueReusableCell(withIdentifier: "sellProductIdentifier") as! sellTableViewCell
cell.IdLabel.text = prodId
cell.nameLabel.text = prodName
return cell
}
目前,在numberOfRowsInSection
,我只是給返回1,因此僅僅顯示一個細胞但我想我的手機添加到一個數組並獲得noOfItems
爲陣的個性化......
希望有人能幫助... :)
編輯:
我真正想要實現的是,當我點擊一個集合視圖項時,會顯示一個tableviewcell,當我返回並單擊第二個集合視圖項時,應該顯示兩個tableview單元,每個tableview單元都具有來自第一個第二個collectionview單元格。
不清楚你的問題。你想製作一組單元格並將其顯示正確? – Arrabidas92
是的,@ Arrabidas92 ..但自從結構被使用我有點困惑... – bws
你需要傳遞的不僅僅是一個結構到視圖控制器 –