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

4

1 回答 1

0

不要使用单元来保持持久的控制器状态。而是保留一个NSArray并将NSIndexPath每个选定单元格添加到您的数组中(如果/当用户取消选择一个单元格时删除它们)。

然后cellForRowAtIndexPath:只需确保根据其索引路径是否在所选单元格数组中正确配置单元格。

于 2012-09-07T11:04:50.577 回答