【发布时间】:2017-08-20 16:28:20
【问题描述】:
我查看了几个与此相关的 StackOverflow 问题,但似乎还没有很好地理解这个概念。
我有一个表格视图,其中包含我使用枚举填充的几个单元格。当我向下滚动行时,表格中的另一行被选中。我实现了以下方法:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("activityCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = activities[indexPath.item].rawValue;
return cell;
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath);
cell?.selected = true;
}
我知道细胞是可重复使用的,但我无法正确理解这个概念以及它是如何应用的。
你能给我一些帮助吗?
干杯
【问题讨论】:
-
那么问题是在您不希望在表格中向上滚动时选择多个单元格吗?
-
一种 'selectedCells' 数组保存选定单元格的索引... 然后调用 cellForRowAtIndexPath 方法,它可以检查该索引是否在数组中,从而将单元格设置为选定。 . 想到的第一个想法:)