getting the selected object from an NSTableView causes problems
getting the selected object from an NSTableView causes problems
- Subject: getting the selected object from an NSTableView causes problems
- From: Daniel Richman <email@hidden>
- Date: Fri, 20 Jun 2008 19:51:21 -0700
Hi All,
I've got an NSTableView that displays the data in an NSMutableArray.
(The program is a to-do list.) I just tried adding a function to allow
you to delete an item: you select the item in the table and then click
delete. My code is as follows:
- (IBAction)deleteItem:(id)sender
{
int selectedRow = [((NSNumber *)[tableView selectedRow]) intValue];
NSLog(@"Selected row is %d", selectedRow);
if (selectedRow != -1) {
NSLog(@"Deleting '%@'", [toDoList objectAtIndex:selectedRow]);
[toDoList removeObjectAtIndex:selectedRow];
[tableView reloadData];
}
}
The problem is that if I try to delete any item other than the very
first one (index 0), the program crashes. I did some log work, which
revealed that the first line is causing problems (int selectedRow...).
But that doesn't explain why the deleting the first item works ok. I'm
stumped. Any ideas?
My project is online at
http://danielrichman.com/tmp/DataSourceChallence_ToDoList.zip .
Thanks,
--Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden