0

I have a UITableView with two sections and I have a button which changes the tableview to edit mode but only the bottom section is editable.

When I select rows and scroll only in the bottom section (which is in edit mode) the rows keep there selection. But if I scroll up until the bottom section is hidden and return back the bottom section the selection has been cleared.

The scrolling between the sections clears the selection.

Why is this happening? How can this be fixed?

daniel3223
  • 141
  • 1
  • 9

1 Answers1

0

So just for posterity. In general even if tableview cells are the same class if they have different behaviour when it comes to things like editabilty it's often better to have two separate CellIdentifier strings to avoid a lot of switching between states.

Can be as simple as

static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier2 = @"Cell2";


NSString *identifierString = indexPath.section == 0 ? CellIdentifier:CellIdentifier2;

MYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierString];

if (!cell)
    cell = [[MYTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierString];
Magoo
  • 2,552
  • 1
  • 23
  • 43