开发者

Deleting a selected NSTableView row from Core Data?

开发者 https://www.devze.com 2022-12-14 23:37 出处:网络
How would I delete selected NSTableView row and it\'s corresponding Core D开发者_JAVA百科ata entry?Assuming your NSTableView is bound to an NSArrayController (which is the most common pattern when dea

How would I delete selected NSTableView row and it's corresponding Core D开发者_JAVA百科ata entry?


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];


You can remove the row using the method tableView:setObjectValue:forTableColumn:row: of NSTableViewDataSource, and then forcing the table to be updated using the method reloadData of NSTableView.

0

精彩评论

暂无评论...
验证码 换一张
取 消