0

I'm developing an app that represents a huge amount of data using UITableView with a custom UITableViewCell.

When the tableView is set to editing mode, it supports multiple selection for further usage of the selected set of data.

Using -tableView:didSelectRowAtIndexPath: and didDeselect I'm changing the rows UIImageViews image to a little tick and storing the selection into an array. When selecting a cell it gets light blue background (iOS standard).

When I'm now scrolling down and up again, the cells background is still light blue but the image is reset to default and the cells isSelected property is NO. Selecting it again invokes the -tableView:didSelectRowAtIndexPath: method.

After a while debugging it turned out that the reusable identifier was wrong. But as I corrected it, scrolling down repeated the same 12 cells over and over again. And the isSelected property is still reset to NO.

How can I maintain selected rows while scrolling the tableView?! And: Why is the cell blue highlighted (or marked as selected) but the isSelected property gets reset to No?

Thanks for help, with kind regards, Julian

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107

1 Answers1

0

Don't use the cell to hold persistent controller state. Instead keep an NSArray and add the NSIndexPath of each selected cell to your array (and remove them if/when the user deselects a cell).

Then in cellForRowAtIndexPath: just make sure you configure the cell correctly based upon whether or not its index-path is in your array of selected cells.

aroth
  • 54,026
  • 20
  • 135
  • 176
  • I actually have an array with the indexPaths of the selected rows. One of the problems is that the cells just keep their light blue "selected color" on their own. I can't control it… – Julian F. Weinert Sep 07 '12 at 14:15
  • Are you calling `deselectRowAtIndexPath:` for the ones you want to stop appearing as selected? – aroth Sep 07 '12 at 21:49
  • Yes, I am. The problem is that the cells appear to be selected, but clicking them invokes the `didSelectRowAtIndexPath` method. – Julian F. Weinert Sep 10 '12 at 09:31
  • Well I don't think allowing the cell to appear selected will do anything to suppress `didSelectRowAtIndexPath` from being called if the user taps it again. It will always be called, unless the table is in 'editing' mode. – aroth Sep 10 '12 at 10:01