Да, вы можете, ниже вы найдете решение для обеих проблем ..
1) добавьте кнопку в cellforrow и используйте метод add target. поэтому всякий раз, когда вы нажимаете на кнопку, он вызывает ваш метод действия. поэтому, не используя метод didselect, вы можете запустить свое действие.
вы можете использовать вот так ...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
//add button here programatically or in your storyboard tableviewcell
cell.btnTemp.tag = indexPath.section
cell.btnSelect.addTarget(self, action: #selector(CallyourDesireButtonAction(_:)), for: .touchUpInside)
}
@objc @IBAction func btnSelectBillingAddressClicked(_ sender: UIButton)
{
//Perform your action for switch
}
2) вы можете использовать следующий код:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if let cell = tableView.cellForRow(at: indexPath) as? YourTableViewCell
{
cell.contentView.backgroundColor = UIColor.red
}
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
{
if let cell = tableView.cellForRow(at: indexPath) as? YourTableViewCell
{
cell.contentView.backgroundColor = UIColor.white
}
}