Challenge - my solution to delete multiple rows at once

Initially I took an approach similar to most here using the seletedRow property in a method such as this one removeObjectAtIndex:[self.taskTable selectedRow]] however, I wanted a way to deleted multiple rows at once. This is possible via an index set (NSIndexSet) as shown:

[code]- (void)removeTask:(id)sender {

NSLog(@"Delete Task Button Clicked!");
// If no array, quit
if (!self.tasks) {
    NSLog(@"No tasks to delete yet");
NSIndexSet *selectedRows = self.taskTable.selectedRowIndexes; // using the selecteRowsIndexes  property (an NSIndexSet)
[self.tasks removeObjectsAtIndexes:selectedRows]; // <-- remove indexset from array
[self.taskTable reloadData]; // refresh tableview

[self updateChangeCount:NSChangeDone];


Needless to say, you must edit the properties for the tableview in interface builder to allow for multiple selections

1 Like