【发布时间】:2018-09-18 20:09:43
【问题描述】:
我需要在 tableview 自定义单元格中放置一个单选按钮。每当用户单击 tableview 单元格或按钮时,单选按钮都需要工作。我尝试使用下面的代码,但没有很好地执行。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as! TableViewCell
cell.country.text = self.animals[indexPath.row]
cell.selectionStyle = UITableViewCellSelectionStyle.none;
if selectedRows.contains(indexPath)
{
cell.radioButton.setImage(UIImage(named:"check.png"), for: .normal)
}
else
{
cell.radioButton.setImage(UIImage(named:"uncheck.png"), for: .normal)
}
return cell
}
【问题讨论】:
-
什么不起作用?发生了什么?你预期会发生什么?在代码中放置断点会发生什么?阅读How to Ask 和minimal reproducible example 并更新您的问题。
标签: ios swift uitableview