如何通过在同一UITableViewCell上单击另一个UIButton来禁用UIButton

时间:2019-06-17 13:13:58

标签: ios swift uitableview

在一个单元格中,有三个按钮:“家人”,“朋友”,“接受”。最初,“接受”按钮被禁用,其余的被启用。我想做的是,当用户单击“家庭接受”按钮时,应启用“好友”按钮。

我尽了一切..仍在尝试并寻找解决方法

{    
   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 个答案:

答案 0 :(得分:1)

您需要在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...
    }
}

将上述代码中的IBOutletsIBActions连接到friendRequestCell's .xib