所以我想从该tableViewCell启用/禁用按钮:

class CommonPromoCell: UITableViewCell {
@IBOutlet weak var optionBtnCommon: UIButton


当从其他tableViewCell启用/禁用其他按钮时

 class PromoButtonCell: UITableViewCell {
 @IBOutlet weak var option1Btn: UIButton!
 @IBOutlet weak var option2Btn: UIButton!
 @IBOutlet weak var option3Btn: UIButton!


因此,主要是我想选择从选项1到选项3中的一个来启用optionBtnCommon,而从上面的三个按钮中都没有选择禁用它。

我尝试过类似的东西

var viewController: PromoButtonCell?

// TODO : DISABLE COMMON BUTTON WHEN NO OTHER IS SELECTED
        if (viewController?.option1Btn.isSelected)! || (viewController?.option2Btn.isSelected)! || (viewController?.option3Btn.isSelected)! {
            optionBtnCommon.isEnabled = true
        } else {
            optionBtnCommon.isEnabled = false
        }


如果写在func#selectorself.optionBtnCommon.addTarget

编辑:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let currentPackage = self.packages[indexPath.section]
    switch indexPath.row {

    case 1:
        let cell = tableView.dequeueReusableCell(withIdentifier: "PromoButtonCell") as! PromoButtonCell
        cell.populate(currentPackage)
        cell.contentView.tag = (indexPath.section + 1) * 10
        return cell

    case 2:
        let cell = tableView.dequeueReusableCell(withIdentifier: "CommonPromoCell") as! CommonPromoCell
        cell.populate(currentPackage, forPayment: self.payments[self.paymentIndex].type)
        cell.optionBtnCommon.tag = indexPath.section
        return cell


谢谢。

最佳答案

如果用户可以更改option1Btn和option2Btn的状态,则需要在PromoButtonCell和视图控制器之间实施某种事件处理,以修改CommonPromoCell的状态。

我将创建一个协议,以便PromoButtonCell可以通知您的viewController单元状态已更改。假设您使用PromoButtonCellDelegate之类的事件创建promoButtonCell:UITableViewCell didSelectButton: UIButton

然后,viewController可以实现该协议,并在接收事件时尝试访问另一个CommonPromoCell来更改其状态。

听起来怎么样?

09-25 17:32
查看更多