作为第一你tableView
需要选择单元格,单元格中的一个被选中后,你想其他细胞不同的是所选单元格不选择,对于您可以创建NSIndexPath
类的一个实例属性,并使用它来存储在didSelectRowAtIndexPath
之内,并且像这样比较它在cellForRowAtIndexPath
里面的值。
var selectedIndexPath: NSIndexPath?
的cellForRowAtIndexPath
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! CustomCell
if (self.selectedIndexpath != nil) {
if self.selectedIndexpath == indexPath {
cell.userInteractionEnabled = true
}
else {
cell.userInteractionEnabled = false
}
}
else {
cell.userInteractionEnabled = true
}
return cell
}
didSelectRowAtIndexPath方法
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if self.selectedIndexpath != indexPath {
self.selectedIndexpath = indexPath
}
else {
self.selectedIndexpath = nil
}
tableView.reloadData()
}
注:我有,如果你选择增殖的细胞的细胞userInteractionEnabled
再次设置为true。
您是否阅读过表格视图委托方法? – Desdenova
你建议使用哪一个来完成它? – DCDC
禁用单元格选择的那个。 – Desdenova