I’m working on an iOS 5 project and I’m using a table view to select items that will be added in a set.
I correctly set AllowsMultipleSelectionDuringEditing to YES to have the bullets on left side and the contentView indented.
Now, my problem is that I have a list of pre-selected items that the user should see when entering in edit mode. I looked inside the documentation, but I didn’t find anything about it, for a way to preselect a list of index paths when entering in edit mode with multiple selection enabled. Is there a way provided by Apple to pre-select a certain number of items or should I develop this feature by myself?
Ok, I found out how to do it and a good and elegant way, it was simpler than excepted:
UITableView has the method
selectRowAtIndexPath:animated:scrollPosition:that select a row.The best way to accomplish what I was looking for is to create an
NSSetofNSIndexPathsand, immediately after setting theUITableViewin editing mode, iterate the set and select the cell one-by-one.For example in this way:
and then, for select the items int the table view:
I hope this may help someone else.