I need to remove the current selected item in tableview. I have linked the button to a method I’ve created (removeTask) but I don’t know how to make it delete the current selection. If i use removeObjectAtIndex:0 it’ll only delete the very top which kind of works but I would like to know how to delete the current selected item. Thanks!
(void)addTask:(id)sender
{
//NSLog(@“Add Task button clicked!”);
// If there is no array yet, create one
if (!self.tasks) {
self.tasks = [NSMutableArray array];
}
[self.tasks addObject:@“New Item”];
// -reloadData tells the table view to refresh and ask its dataSource (which hapens to be this BNRDocument object in this case) for new data to display
[self.taskTable reloadData];
// -updateChangeCount: tells the application wheather or not the document has unsaved changes, NSChangeDone flags the document as unsaved
[self updateChangeCount:NSChangeDone];
}
You could also use NSIndexSet in case the user selects more than one row From BNRDocument.m
[code]- (void)deleteTask:(id)sender
{
//Find out which tasks are being selected for removal
NSIndexSet *selectedRows = [self.taskTable selectedRowIndexes];
//Remove objects from the tasks array corresponding to the indexes for the selected rows
[self.tasks removeObjectsAtIndexes:selectedRows];
//Refresh the table view and tell application about unsaved changes
[self.taskTable reloadData];
[self updateChangeCount:NSChangeDone];
I guess there’s more in updateChangeCount:NSChangeDone, if you delete it from the deleteTask: method, when you re-run the application the changes does not take effect unless you finish with that. So, can anyone explain me? It will be very helpful, thanks!!!