У меня есть кнопка с именем btnChk2 .Я хочу, чтобы когда пользователь нажимал btnChk2 , чтобы была выбрана кнопка btnChk .Вот мой код, то, что происходит в моем коде, заключается в том, что при нажатии btnChk2 btnChk2 выбирается, а не btnChk .
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CheckBoxCell")
if let lbl = cell?.contentView.viewWithTag(1) as? UILabel {
lbl.text = "item-\(1)"
}
if let btnChk = cell?.contentView.viewWithTag(2) as? UIButton {
btnChk.addTarget(self, action: #selector(checkboxClicked(_ :)), for: .touchUpInside)
}
if let btnChk2 = cell?.contentView.viewWithTag(100) as? UIButton {
btnChk2.addTarget(self, action: #selector(checkboxClicked(_ :)), for: .touchUpInside)
}
return cell!
}
@objc func checkboxClicked(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
}