Каждое представление коллекции использует одну и ту же пользовательскую ячейку с xib. В этом xib у меня есть кнопка.
Имена коллекций
Код: Выделить всё
1) manPerfumeCV
2) womanPerfumeCV
3) kidsPerfumeCV
Код: Выделить всё
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)
}
Код: Выделить всё
1) manPerfumeData
2) womanPerfumeData
3) kidPerfumeData.
Хотя, если я нажмите кнопку во втором или третьем представлении коллекции, приложение выйдет из строя.
Есть ли способ узнать, из какого представления коллекции они нажали кнопку, чтобы я мог загрузить конкретный массив [Продукты]?
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/419 ... and-button