简体   繁体   中英

How to disable UIButton by clicking another UIButton on same UITableViewCell

In a cell there are three buttons: Family, Friend, Accept. Initially Accept button is disabled and rest are enabled. What I want to do is when a user clicks on Family- Accept button should be enabled and Friend button should be disabled.

I tried everything.. still trying and searching for solution

{    
   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
}

You need to do that in your friendRequestCell . Listen to all the button actions on the friendRequestCell , ie

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...
    }
}

Connect the IBOutlets and IBActions in the above code to the friendRequestCell's .xib .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM