【发布时间】:2019-08-05 05:35:35
【问题描述】:
我制作了一个 tableviewcell,里面有一个按钮。我在 tableviewcell.swift 类中连接了按钮的 IBAction。然后我做了一个委托并像这样访问 viewcontroller 类中的按钮触摸操作..
func optionTap(cell: SlideUpTableViewCell) {
if let indexPath = tableview?.indexPath(for: cell) {
}
}
但我想要实现的是,我希望一次只选择一个复选框按钮。我有 3 行,现在我可以点击 3 个按钮中的每一个,而我一次只想点击 1 个按钮。即,如果我点击第一个单元格上的按钮,然后点击第二个单元格中的按钮,则应自动取消选择第一个单元格按钮。简而言之,正常的单选是如何工作的……
这个我试过了...但是不行...
func optionTap(cell: SlideUpTableViewCell) {
if let indexPath = tableview?.indexPath(for: cell) {
if selectedArrayIndex.contains(indexPath.row) {
selectedArrayIndex.remove(at: selectedArrayIndex.index(of: indexPath.row)!)
cell.checkBobButton.tintColor = ThemeManager.current().inactiveGrayColor
cell.checkBobButton.setImage(UIImage(named: "circle_stroke"), for: .normal)
} else {
selectedArrayIndex.append(indexPath.row)
cell.checkBobButton.tintColor = ThemeManager.current().secondaryColor
cell.checkBobButton.setImage(UIImage(named: "circle_tick"), for: .normal)
}
}
}
编辑 1: 这是 cellForRow..
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: SlideUpTableViewCell = tableView.dequeueReusableCell(withIdentifier: cellID) as! SlideUpTableViewCell
cell.delegate = self
cell.selectionStyle = .none
cell.headingLabel.text = self.arrData[indexPath.row].heading
cell.subHeadingLabel.text = self.arrData[indexPath.row].subHeading
return cell
}
编辑 2 这就是 UI 的外观......
【问题讨论】:
-
添加一些额外的代码
-
好的@Anbu.Karthik ..但这就是我的困惑..:)
-
显示你的 cellforRow
-
我已经用 cellForRow..@Anbu.Karthik 编辑了问题
-
@asd2,对于单选使用 didSelectRowAtIndex 路径函数。
标签: ios swift uitableview uibutton