所以我想从该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
的#selector
的self.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
来更改其状态。
听起来怎么样?