views:

38

answers:

1

hi Frnz,

i want to delete multiple rows from a table view based on users selection.obviously i cant use didSelectRowAtIndexPath method coz it will be called for every row selected. i want to allow user to select multiple rows for deletion and then delete them in one go...Is it possible if yes then how to go about it.Also i am using a single view based project and i want the header of table view changed to "Delete" on the same view when the user want to delete the rows from the view.

Thx

A: 

You can do something this way:

- (void)tableView:(UITableView *)theTableView
      didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {

[theTableView deselectRowAtIndexPath:[theTableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [theTableView cellForRowAtIndexPath:newIndexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [selectedCellsMutableArray addObject:newIndexPath];
} else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    cell.accessoryType = UITableViewCellAccessoryNone;
    [selectedCellsMutableArray removeObjectIdenticalTo:newIndexPath];
}

}

When user press Delete Selected button - just invoke something like

// change your model here and then:
[yourView deleteRowsAtIndexPaths:selectedCellsMutableArray withRowAnimation:UITableViewRowAnimationRight];
OgreSwamp