Re: Reading/Writing Data From NSTableView
Re: Reading/Writing Data From NSTableView
- Subject: Re: Reading/Writing Data From NSTableView
- From: "M. Uli Kusterer" <email@hidden>
- Date: Sat, 29 Jan 2005 08:06:49 +0100
At 22:42 Uhr -0800 28.01.2005, mmalcolm crawford wrote:
On Jan 28, 2005, at 10:30 PM, Kirt Cathey wrote:
I managed to get data to display on an NSTableView with bindings or
by calling all the proper methods as outlined in many tutorials.
However, I need to write the contents to a text file when the user
presses a 'save' button within the same view.
Is there not a quick way of doing this? Would really like to know
how to do this with bindings, but without have to go through the
encoder/decoder process.
Bindings has nothing to do with data archival. You still have to
write the appropriate code, typically ensuring that your model
objects conform to the NSCoding protocol etc., see
<http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/index.html>
Shouldn't be too hard to archive in a generic way, though. Just
create a subclass of NSDocument (e.g. UKArchivingDocument) and give
it an
IBOutlet NSObjectController * controllerToArchive;
And then implement the following methods:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
return [NSArchiver archivedDataWithRootObject:
[controllerToArchive content]];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
id content = [NSUnarchiver unarchiveObjectWithData: data];
[controllerToArchive setContent: data];
return YES;
}
Shouldn't be much more to do if your objects comply to NSCoding,
which most of the Foundation objects do.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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