我有一个UITableView
,启用了多项选择。
我的一些细胞不会被选中。对于我实施的人:
tableView:cellForRowAtIndexPath:
中的
我设置cell.selectionStyle = UITableViewCellSelectionStyleNone;
并在tableView:didSelectRowAtIndexPath:
我打电话给[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
。
这很好用。我唯一需要注意的是,细胞左侧的小圆圈仍然出现。当用户点击单元格时不会检查它,但是当单元格“无法选择”时,我希望不显示它。
如何隐藏某些单元格的圆圈?
由于
答案 0 :(得分:3)
您必须在表视图数据源中实现tableView:canEditRowAtIndexPath:
方法。它可以让你阻止你想要编辑的单元格,从而不会显示圆圈。
请注意,设置cell.selectionStyle = UITableViewCellSelectionStyleNone;
不会阻止选择单元格。它只是删除了所选单元格上的任何视觉线索。
答案 1 :(得分:0)
试试这个......
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if([[tableView indexPathsForSelectedRows] containsObject:indexPath]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
答案 2 :(得分:-1)
子类化UITableViewCell
并添加以下方法对我而言有效:
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(false, animated: true);
}