我有一個具有多個集合視圖的視圖控制器。具有相同XIB單元格和按鈕的多個集合視圖
每個集合視圖與xib使用相同的自定義單元格。在這個xib中,我有一個按鈕。
的collectionViews名
1) manPerfumeCV
2) womanPerfumeCV
3) kidsPerfumeCV
裏面cellForItemAt
我有cell.productCart.tag = indexPath.row
let cell:iPhoneCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "iPhoneCell", for: indexPath) as! iPhoneCollectionViewCell
if collectionView == self.womanPerfumeCV {
let prods = womanPerfumeData[indexPath.row]
cell.configureCell(products: prods)
cell.productCart.tag = indexPath.row
} else if collectionView == self.manPerfumeCV {
let prods = manPerfumeData[indexPath.row]
cell.configureCell(products: prods)
cell.productCart.tag = indexPath.row
} else if collectionView == self.kidsPerfumeCV {
let prods = kidsPerfumeData[indexPath.row]
cell.configureCell(products: prods)
cell.productCart.tag = indexPath.row
}
,並在同一個視圖控制器我從廈門國際銀行文件,這個動作按鈕
@IBAction func iPhoneAddToCart(_ sender: AnyObject) {
let butt = sender as! UIButton
let indexP = IndexPath(row: butt.tag, section: 0)
let cell = manPerfumeCV.cellForItem(at: indexP) as! iPhoneCollectionViewCell
print(manPerfumeData[indexP.row].price)
}
每個集合視圖都有自己的[Products] ar射線。
1) manPerfumeData
2) womanPerfumeData
3) kidPerfumeData.
在,如果我輕按按鈕,在與manPerfumeData一號集合視圖它打印的價格非常好我的代碼。
雖然如果我按下第二個或第三個集合視圖上的按鈕應用程序崩潰。
有沒有什麼辦法從極地收集視圖知道他推動按鈕,所以我可以加載spesific [產品]數組??
謝謝!
你怎麼在調試器輸出看到加選擇? –
@SinaKH致命錯誤:意外發現零,同時展開一個可選值 2017-01-30 14:25:38.928171 Aromania [19538:6823926]致命錯誤:意外地發現零,同時展開一個可選值 因爲在'print'我只有'manPerfumeData'。 如何識別按鈕按下哪個集合視圖? –