【发布时间】:2017-12-15 09:51:09
【问题描述】:
所以我想启用/禁用该 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,而当上述 3 个按钮中的任何一个都没有被选择来禁用它时。
我尝试过类似的东西
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
}
如果写在#selector 的#selector 的func 的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
谢谢。
【问题讨论】:
-
var viewController: PromoButtonCell?的实例保存在哪里以及如何保存? -
我已经在
CommonPromoCell: UITableViewCell中声明了它。忘了说当强制解开它时它会崩溃 -
@FagadaruMarcel 请给我看你的TableView。你不能像上面评论中所说的那样做这样的事情。
-
我的 mainTableVIew 到底是什么?
-
@dahiya_boy 我已经编辑了我的问题,如果这就是你要找的东西
标签: ios swift uitableview swift3