Re: MyDocument and NSArrayController
Re: MyDocument and NSArrayController
- Subject: Re: MyDocument and NSArrayController
- From: email@hidden
- Date: Mon, 10 Jan 2005 22:39:04 +0000
>> I would like to set up MyDocument (subclass of NSDocument) to get
>> notification of changes in an NSArrayController. Is this possible? How
>> can get notif's of when the selection changes and when objects are
>> added or removed from the NSArrayController?
>>
>> Alex
>
> I'm doing something similar with an NSApp delegate (my project is not
> document based). I set up KVC-compliant accessors to an array in my class
> and then created a binding to the NSArrayController's "selectedObjects" key
> path, like so:
>
> [self bind:@"myArrayKey" toObject:theArrayController forKeyPath:@"selectedObjects" options:nil];
>
> When a selection is made, my class gets an array containing the selected
> objects. Since my views only allow single selections, I just pull out the first
> array element.
And to answer your second question about picking up additions and removals (sorry I didn't re-read your message until after I sent my first reply), you could try a binding from your class to the NSArrayController's "arrangedObjects" key path. I haven't tried it, though, and it might be better just to observe the class object that's adding the items -- unless it's one of many buried within an object hierarchy.
_______________________________________________
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