Core Data, NSTableView and getting Selected Row Value
I'm pretty new to Core Data and managed to get the NSTableView to show my Core Data values. The entity that the table uses is Emotes that have the two properties, Emote (string) and Usage (integer 16)
When a user selects a item, it will allow a person to copy that emote to clipboard. In order to do that, I need to get the ManagedObject of the selected row and send the Emote value in the object to the clipboard. I got the clipboard part, but stuck on the part in retrieving the data of the selected row from 开发者_如何转开发the data source.
What is the easiest way in getting the value of the selected row?
What is the easiest way in getting the value of the selected row?
The easiest way is to query the NSArrayController for
- (NSArray *)selectedObjects
You don't have to worry about what rows are selected; the table view will tell you what rows to copy by sending you (the data source) a tableView:writeRowsWithIndexes:toPasteboard:
message.
Whatever you do in your implementation of tableView:objectValueForTableColumn:row:
, you'll implement that method pretty much the same way, except that instead of retrieving and returning a single column value, you'll write (or at least promise) all of them at once, in whatever formats make sense, to the pasteboard.
精彩评论