Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to configure a UITableView to allow multiple-selection?

For the iPhone, is it possible to configure a UITableView such that it will allow multiple-selection?

I've tried overriding -setSelected:animated: for each UITableViewCell, but trying to fudge the required behavior is tricky as it's difficult to separate the real unselections from the ones where the UITableView thinks I've unselected due to selection of another cell!

Hope someone can help!

Thanks,

Nick.

like image 698
Nick Cartwright Avatar asked Nov 21 '08 06:11

Nick Cartwright


2 Answers

Following property should work fine if you are developing app for iOS5.0+

self.tableView.allowsMultipleSelection = YES; 
like image 174
Hamdi Avatar answered Sep 21 '22 14:09

Hamdi


The best way to do this would be to a checkmark per selected row.

You can do that by setting the accessoryType on the selected UITableViewCell instances to UITableViewCelAccessoryCheckmark.

To deselect the row, set it back to UITableViewCellAccessoryNone.

To enumerate which cells/rows were selected (say, upon clicking a button), simply iterate over the cells of the table looking for UITableViewCellAccessoryCheckmark. Or, manage some NSSet or the like in your table view delegate in the "did select" delegate methods.

like image 34
z8000 Avatar answered Sep 23 '22 14:09

z8000