【发布时间】:2017-11-02 14:18:51
【问题描述】:
我有一个UITableViewCell。在 TableViewCell 中,我在单行中有 7 个按钮。我想播放音乐。当我按下button1时,它的背景颜色应该改变。如果我按下 button2,它的背景颜色应该改变,并且 button1 将被取消选择。我还为每个按钮设置了标签,但我不明白,怎么办?声音播放正常,但我无法选择和取消选择按钮。我正在使用swift3。提前致谢。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> tableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PlayerCell") as! tableViewCell
cell.Btn_one.addTarget(self, action: #selector(TableViewController.BtnAction_One), for: .touchUpInside)
//For example
if (cell.Btn_one.tag == 1){
cell.Btn_one.backgroundColor = .white
}else if (cell.Btn_two.tag == 2){
cell.Btn_two.backgroundColor = .red
}
}
@IBAction func BtnAction_One(_ sender: UIButton) {
self.play()
}
【问题讨论】:
标签: ios uitableview swift3 tableviewcell