views:

283

answers:

1

How would I delete selected NSTableView row and it's corresponding Core Data entry?

+3  A: 

Assuming your NSTableView is bound to an NSArrayController (which is the most common pattern when dealing with Core Data), you can just use NSArrayController's remove: method:

[theArrayController remove:self];

This will delete all objects which are selected in the array controller.


Otherwise, if you're not bound to an NSArrayController, you'll need to deal with the selected object directly. Without knowing how you're populating your tableView, I can't show all of the necessary code, but presumably you can find which NSManagedObject is selected. Once you have that object, it's a cinch to delete it:

NSManagedObjectContext *moc = the managed object context for your objects;
NSManagedObject *selectedObject = the currently-selected object;
[moc deleteObject:selectedObject];
Matt Ball