我在uitableview中遇到问题,只要我选择一个单元格4没有单元格自动获取选择...我厌倦了这个问题有人请帮助这里是我的didselectrowfunc ..UItableview一次点击多个单元格正在检查迅速3
FUNC的tableView(_的tableView:UITableView的,didSelectRowAt indexPath:indexPath){
////////////////添加复选框///////// ///////////////
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.checkmark
{
if selectedDisease.count > 0
{
let no = selectedDisease.index(of: finall[indexPath.row])
selectedDisease.remove(at: no!)
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none
print(selectedDisease)
}
else
{
selectedDisease = [""]
}
}
else
{
if selectedDisease.contains("")
{
selectedDisease.removeAll()
var name = finall[indexPath.row]
selectedDisease.append(name)
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
print(selectedDisease)
}
else
{
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
selectedDisease.append(finall[indexPath.row])
//selectedDisease = [finall[indexPath.row]]
print(selectedDisease)
}
}
}
///////// CellForRowAt ///////////////
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "diseasetable", for: indexPath) as! FoodTableViewCell
cell.DiseaseName.text = finall[indexPath.row]
//indexsave.append(indexPath.row)
return cell
}
这是因为表格单元格是reusable.What你想干什么? –
我想让用户选择多种疾病,但问题是如何做到这一点,通过这种代码自动选择不同的细胞..... **我知道它是重用细胞,但如何克服这一点,当表重用细胞它是未检查** –
添加cellForRow方法的代码 –