Re: Bindings, TableViews, and saving...
Re: Bindings, TableViews, and saving...
- Subject: Re: Bindings, TableViews, and saving...
- From: mmalcolm crawford <email@hidden>
- Date: Mon, 26 Jul 2004 21:25:04 -0700
On Jul 26, 2004, at 7:56 PM, James McConnell wrote:
I'm working on a fairly common project where I have a table view
using an NSArrayController to handle custom model objects. I can hook
up
all the bindings correctly like in the tutorials, but what I'd like to
be
able to do is to take the information from the TableView and save it
to disk
as a custom file type. How would I go about this?
The same as you would a non-bindings application: make your custom
objects archivable and archive the array (or in the general case, the
root object)...
For example, starting with the Shopping List example at
<
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>
you might implement suitable get/set accessors for itemsArray then
something conceptually similar to:
- (IBAction)save:sender
{
NSString *path =
[@"~/Library/Application Support/MyApp/MyAppsData"
stringByStandardizingPath];
[itemsArray writeToFile:path atomically:YES];
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
NSString *path =
[@"~/Library/Application Support/MyApp/MyAppsData"
stringByStandardizingPath];
NSArray *array = [[NSArray alloc] initWithContentsOfFile:path];
[self setItemsArray:array];
[array release];
}
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.