func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let identifier = "item"
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! CollectionViewCell
//print("Posicion" , indexPath)
cell.btnCollection.setTitle(String(describing: indexPath), for: UIControlState.normal)
cell.btnCollection.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
return cell
}
I'm creating a button and assign a value as a title in this way
cell.btnCollection.setTitle(String(describing: indexPath), for: UIControlState.normal)
and at the same time I assign a click action to each button
cell.btnCollection.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
and the function that is executed when clicking on the buttons is as follows
@objc func buttonAction(sender: UIButton!) {
//var Alert = UIAlertController(title:"Alert",message: "dsdsd" , preferredStyle: UIAlertControllerStyle.alert)
//self.present(Alert, animated: true, completion: nil)
sender.backgroundColor = UIColor.red
}
I would like to know how I can recover the "title" value of the button I press and show it in the Alert