I'm trying to create UICollectionView with buttons. I can set button titles but target action doesn't work. Below is my code:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TVButtonCell", for: indexPath) as! TVButtonCell
cell.channelButton.setTitle(channelKeys[indexPath.row], for: .normal)
cell.channelButton.addTarget(self, action: #selector(FirstViewController.pressed(_:)), for: .primaryActionTriggered)
return cell
}
func pressed(_ sender: AnyObject) {
print("Button pressed")
}
Does anybody know what am I doing wrong?