Re: Quick way to get contents of NSTableView as text?
Re: Quick way to get contents of NSTableView as text?
- Subject: Re: Quick way to get contents of NSTableView as text?
- From: Jim Hamilton <email@hidden>
- Date: Tue, 23 Aug 2005 13:53:03 -0400
On Aug 23, 2005, at 12:34 PM, Rick Hoge wrote:
I have an NSTableView that is populated during a session in which
the user may add and reorder columns and edit cells. I would like
to grab a text 'snapshot' of the table, which I'd save in an
NSString as a tab-delimited table with minimal formatting.
I tried writing my own method using NSTableColumn's dataCellForRow:
method, expecting to be able to do something like [[myColumn
dataCellForRow:5] stringValue] to get the contents of the fifth row
of a particular table column, but this always returns the same
value regardless of row.
Has anyone seen a nice clean way of dumping a table to text? I
know I can hack something together but all my ideas seem more
complicated than this should be.
Can you just get each cell's datum from the data source?
(NSTableDataSource protocol's -tableView:objectValueForTableColumn:row:)
Or are you using bindings, as in Core Data? Then there is no data
source, and you will need to get it some other way. My solution was
to 1) get the binding info for each NSTableColumn, 2) figure out
_which_ binding was used for the values, and 3) extract the data from
the ultimate source. Step 2 is hard to solve in the general case,
but for a specific column you know which binding you're using.
Read up on the NSKeyValueBindingCreation protocol, especially -
exposedBindings and -infoForBinding: in <http://developer.apple.com/
documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Protocols/
NSKeyValueBindingCreation.html>
Jim H
--
Jim Hamilton
email@hidden
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden