How to detect one button in UITableviewCell, I have 10 UIButton in UITableViewCell, next when I click on UIButton then i
Create protocol
protocol HomeTableViewCellDelegate {
func bookMarkBtnTapped(btn: UIButton)
}
class HomeTableViewCell: UITableViewCell {
@IBOutlet weak var bookMarkBtn: UIButton!
//add delegate var for protocol
var delegate: HomeTableViewCellDelegate?
@IBAction func bookMarkBtnAction(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
if(sender.isSelected == true)
{
sender.setImage(UIImage(named:"favorite_blue"), for: UIControlState.normal)
}
else
{
sender.setImage(UIImage(named:"favorite_white"), for: UIControlState.normal)
}
//set this which button is pressed
self.delegate?.bookMarkBtnTapped(btn: sender)
}
}
HomeViewController implement HomeTableViewCellDelegate method
class HomeViewController: HomeTableViewCellDelegate {
func bookMarkBtnTapped(btn: UIButton) {
// here btn is book mark button tapped by user from tableview cell
}
}