0

I am using UITableView, setting editing true, and using these options in interface builder:

enter image description here

This shows a nice selection UI whose style I can modify and events I can react to:

enter image description here

I want to turn this off, but only for certain cells. I've seen this and many similar questions, but they refer to a different type of selection in UITableView. UITableViewCellSelectionStyle.None and willSelectRowAtIndexPath do not allow me to block this type of selection.

Community
  • 1
  • 1
SimplGy
  • 20,079
  • 15
  • 107
  • 144

2 Answers2

1

Did you try to implement

func tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool

in your delegate ?

I believe it will allow you to obtain the results you are trying to achieve.

Alain T.
  • 40,517
  • 4
  • 31
  • 51
0
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

if(indexPath.row == index of cell you don't want the selection for)
{
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

cell.textLabel.text = [a objectAtIndex:indexPath.row];
return cell;
}

For example:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *a = @[@"md",@"dh",@"kkd",@"dkkls"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

if(indexPath.row == 2)
{
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

cell.textLabel.text = [a objectAtIndex:indexPath.row];
return cell;
}

it won't show selection for "kkd" in your tableview