I have an odd issue cropping up with an NSOutlineView. The view is essentially a list of apps with associated files as children. I populate the view by hand in it's data source and all of that works fine. What I now want to do is have a button to remove an item. In order to do it I implemented a method, removeAppOrFile, like so:
- (IBAction)removeAppOrFile:(id)sender
{
NSInteger selectedRow = [myView selectedRow];
if (selectedRow == -1) //ie. nothing's selected
{
return;
}
NSTableColumn *col = [myView tableColumnWithIdentifier:@"Column 1"];
NSCell *cell = [col dataCellForRow:selectedRow];
NSString *item = [cell stringValue];
NSLog(@"The row is: %ld\nThe column is: %@\nThe cell is: %@\nThe selected item is: %@",selectedRow, col, cell, item); // For testing purposes
}
myView is an IBOutlet connected to my NSOutlineView. If I select a different row and click the button the value for selectedRow will change properly, but the NSCell object never changes, and what should be it's value (ie. NSString item) always shows that of the last visible item (ie. if there's an item with children as the last item NSString item will be the parent if it's not expanded, or the last child if it is expanded).
The weird thing is that I use basically the same code elsewhere for a doubleAction on an NSOutlineView and it works perfectly. In that case, the code is as below:
- (void)editedAppOrFile:(id)sender
{
NSInteger rowNumber = [sender clickedRow];
NSTableColumn *col = [sender tableColumnWithIdentifier:@"Column 1"];
NSCell *cell = [col dataCellForRow:rowNumber];
NSString *item = [cell stringValue];
NSLog(@"The row is: %ld\nThe column is: %@\nThe cell is: %@\nThe selected item is: %@",selectedRow, col, cell, item); // For testing purposes
}
In this case sender is the outlineView. item & cell change with rowNumber change.
Any idea as to why it's not working in the first example?