Selecting multiple rows of a UITableView

12,224

Solution 1

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

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

indexPathsForSelectedRows

Solution 2

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/

Share:
12,224
Roger
Author by

Roger

Updated on June 04, 2022

Comments

  • Roger
    Roger almost 2 years

    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