Как отключить UIButton, нажав другую UIButton на том же UITableViewCell - PullRequest
2 голосов
/ 17 июня 2019

В ячейке есть три кнопки: Семья, Друг, Принять. Изначально кнопка «Принять» отключена, а остальные включены. То, что я хочу сделать, - это когда пользователь нажимает на кнопку Family-Accept, и кнопка Friend должна быть отключена.

Я попробовал все .. все еще пытаюсь найти решение

{    
   let cell = tableView.dequeueReusableCell(withIdentifier: "friendRequestCell") as! friend

   cell.selectionStyle = .none

   cell.accept.addTarget(self, action:  #selector(RequestsViewController.accept) , for: .touchUpInside)
   cell.family.addTarget(self, action: #selector(RequestsViewController.family), for: .touchUpInside)
   cell.friend.addTarget(self, action: #selector(RequestsViewController.friend), for: .touchUpInside)

   return cell
}

1 Ответ

1 голос
/ 17 июня 2019

Вы должны сделать это в вашем friendRequestCell.Прослушайте все действия кнопок на friendRequestCell, т.е.

class FriendRequestCell: UITableViewCell {
    @IBOutlet weak var accept: UIButton!
    @IBOutlet weak var family: UIButton!
    @IBOutlet weak var friend: UIButton!

    @IBAction func onTapFamily(_ sender: UIButton) {
        self.accept.isSelected = sender.isSelected
        sender.isSelected = !sender.isSelected
    }

    @IBAction func onTapAccept(_ sender: UIButton) {
        //add your configuration here...
    }

    @IBAction func onTapFriend(_ sender: UIButton) {
        //add your configuration here...
    }
}

Подключите IBOutlets и IBActions в приведенном выше коде к friendRequestCell's .xib.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...