Iphone – How to select Multiple rows in UITableView


I want multiple selection in UITableView and also its data into one array or in one dictionary…

Best Solution

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

    if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
        [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
        [selectedIndexes addObject:[NSNumber numberWithInt:indexPath.row]];
    } else {
        [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
        [selectedIndexes removeObject:[NSNumber numberWithInt:indexPath.row]];

    [tableView deselectRowAtIndexPath:indexPath animated:NO];


selectedIndexes has to be an array where you manage the selected cells indexes and utilize later accordingly.