Roger
Roger

Reputation: 243

Selecting multiple rows of a UITableView

This page http://networkpx.blogspot.com/2009/07/multiple-row-selection-with-uitableview.html

mentions a way to implement table views that can allow multiple selections of rows.

At the time of this article, it seems that it was not a blessed way of doing this.

Now, apparently, Apple is allowing this kind of tableViews.

The article mentions this

NSArray* selectedRows = [tableView indexPathsForSelectedRows];

as a way of getting a list of all rows selected but this is not a legal functionality of the SDK.

The big question is: how do I get a list of all rows selected, so I can perform an action with them?

thanks

EDIT

To answer some questions... this is the code I am using to discover if a row is selected, but this is giving me zero entries.

NSMutableArray *selectedRows = [[NSMutableArray alloc] init];

for (int i=0; i<[list count]; i++) {

 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
 UITableViewCell *aCell = (UITableViewCell*) [myTable cellForRowAtIndexPath:indexPath];
 if (aCell.accessoryType == UITableViewCellAccessoryCheckmark) {
  [selectedRows addObject:indexPath];
 }
}

// selectedRows has always 0 entries... all cells give me their type as UITableViewCellAccessoryNone even those with checkmark

Upvotes: 2

Views: 12234

Answers (3)

ipraba
ipraba

Reputation: 16553

Create a NSMutableArray. Whenever a table cell is selected insert the current indexpath in the array. whenever he deselects the cell remove it from the array. Final array will have everything you selected.

MultipleCheck in Table – UITableView Example with Demo

http://sugartin.info/2011/08/19/multiplecheck-in-table-uitableview/

Upvotes: 1

lxcid
lxcid

Reputation: 1043

Apple will reject your app for for iOS 4 and below.

We found the following non-public API/s in your app:

indexPathsForSelectedRows

Upvotes: 2

Oscar
Oscar

Reputation: 1035

Are you looking to have the user select multiple rows at the same time? If not you could create an array that holds each row that is selected as the user selects them.

Also for the check mark you could just subclass UITableViewCell.

How to subClass UITableViewCell and use it to not clear UILabel background color on UITabeViewCell selected?

Upvotes: 0

Related Questions