i am displaying a list of items in a tableview.i need to select and delete multiple rows from the table at a time,any resources on how to do this
See Question&Answers more detail:osi am displaying a list of items in a tableview.i need to select and delete multiple rows from the table at a time,any resources on how to do this
See Question&Answers more detail:osI'm assuming your table has just one section. You can extend this solution to multiple sections fairly easily.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
toggle the indexPath.row's membership in "selectedRows", like this:NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:indexPath.row];
if ( [self.selectedRows containsObject:rowNsNum] )
[self.selectedRows removeObject:rowNsNum];
else
[self.selectedRows addObject:rowNsNum];
[self.myTableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
EDIT: Here's my full didSelectRowAtIndexPath method. The deselectRowAtIndexPath may be required for correct operation.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ( self.editing )
return;
[self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
NSNumber *rowNsNum = [NSNumber numberWithUnsignedInt:indexPath.row];
if ( [self.selectedRows containsObject:rowNsNum] )
[self.selectedRows removeObject:rowNsNum];
else
[self.selectedRows addObject:rowNsNum];
[self.myTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.2];
}