Re: NSArrayController
Re: NSArrayController
- Subject: Re: NSArrayController
- From: Scott Anguish <email@hidden>
- Date: Thu, 15 Apr 2004 06:19:15 -0400
On Apr 15, 2004, at 3:36 AM, Johan Kool wrote:
Hello,
In a simple app I am trying to get the content of a NSArrayController
saved. Saving seems to work, but opening not. My tableview doesn't get
updated with the saved data, also not after forcing a reloadData.
There are two ways to connect data to data to an NSArrayController..
by setting the content, or by binding the contentArray item to the
object..
I recommend keeping the array value (in your case, the contents of
"MyContent" as a variable of the Document, and then bind the array
controller to the File's Owner MyContent key.
Anyways, that's partly moot in this case.
loadDataRepresentation:ofType: is called before the nib is loaded. So
the nib doesn't have an NSArrayController yet. You need to wait until
the windowControllerDidLoadNib: is done.
So, my fix would be
add a "NSMutableArray *myContent" to your document class, and accessors
for it.
remove the connection to 'content' in IB
bind the array controller's contentArray to that variable on File's
Owner in the nib
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSKeyedArchiver *archiver;
NSMutableData *data = [NSMutableData data];
archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutable
Data:data];
[archiver encodeObject:[self myContent] forKey:@"MyContent"];
[archiver finishEncoding];
return data;
[archiver release];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSMutableArray *mutArray;
NSKeyedUnarchiver *unarchiver;
unarchiver = [[NSKeyedUnarchiver alloc]
initForReadingWith
Data:data];
mutArray = [unarchiver decodeObjectForKey:@"MyContent"];
[self setMyContent:mutArray];
[unarchiver finishDecoding];
[unarchiver release];
return YES;
}
_______________________________________________
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.