I seem to have found a reasonable solution, but I'm a bit confused about why it 
works and other things haven't.

To recap, I'm trying to control an array of dictionaries. Each dictionary 
contains a file name and a checkbox (boolean). The array is stored in a 
@"files" member of the user defaults.

Firstly, it seems that checking "handles content as compound value" for the 
array controller seems to help, because any change (even just the checkbox) 
then triggers a full update to the model, and I can get notified that the top 
level array has changed.

Now if I bind my NSArrayController to my NSPreferencesController subclass, with 
Controller key = "values" and key path = "files", it notifies on any update, 
including just the checkbox. However it doesn't accept external changes to the 
user preferences. If I change and set the "files" attribute of the User 
Defaults, it doesn't update.

BUT...

if I kind of proxy the values, and have this in my preferences controller:

-(NSArray *)files {
        return [[[self values] valueForKey:@"files"] makeCollectionMutable];
}

-(void)setFiles:(NSArray *)files {
        [[self values] setValue:files forKey:@"files"];
}

and I have an observer for the user defaults:

- (void)observeValueForKeyPath:(NSString *)keyPath 
                                          ofObject:(id)object 
                                                change:(NSDictionary *)change 
                                           context:(void *)context { 
        if ([keyPath isEqualToString:@"files"]) {
                [self didChangeValueForKey:@"files"];
        }
}

Now instead I link my NSArray Controller to Controller key = "files" and key 
path = "" (blank), now it seems to work fine bi-directionally.

Which is good, but I don't understand why it should work differently to just 
having Controller key = "values" and key path = "files".

It seems like the way the bindings work is it is listening to changes to 
"values" but not changes to "values.files". It seems like what I need is 
Controller key = "values.files" and key path = "" (blank). But IB doesn't seem 
to allow the controller key to be a dotted value.

Am I thinking about this wrong somehow? Can I get the bindings to listen to 
changes to values.files without having to proxy it through my own methods?



--- On Thu, 9/18/08, Chris Idou <[EMAIL PROTECTED]> wrote:

> From: Chris Idou <[EMAIL PROTECTED]>
> Subject: Re: Listening for changes in a table
> To: cocoa-dev@lists.apple.com
> Date: Thursday, September 18, 2008, 8:27 PM
> --- On Thu, 9/18/08, Ken Thomases
> <[EMAIL PROTECTED]> wrote:
> 
> > Two possibilities:
> > 
> > * If you used a custom class rather than a dictionary,
> then
> > there  
> > would be a setter of your own design called when the
> > property is set  
> > due to a change in the checkbox.  
> 
> Yes I could do that, but given that I'm storing the
> result in the user preferences, and the user preferences can
> store dictionaries but not objects, I was hoping to stay
> with dictionaries.
> 
> Maybe I should try inheriting from NSMutableDictionary or
> something.
> 
> > * Your controller can use KVO to observe the property
> to
> > which the  
> > checkbox is bound.  Then it will receive change
> > notifications when the  
> > property is changed.
> 
> Would that mean observing every single dictionary in the
> array and adding and removing observers as the array expands
> and contracts? Sounds fiddly.
> 
> --- On Thu, 9/18/08, I. Savant
> <[EMAIL PROTECTED]> wrote:
> 
> >    Why does everybody forget about / ignore
> > <NSTableDataSource>?
> 
> I'm a bit vague on how a DataSource and an
> ArrayController work together. Do you choose one or the
> other? In any case, it sounds like a fairly fiddly option
> too.
> 
> 
> 
> 
> 
>       
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to
> the list.
> Contact the moderators at
> cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/idou747%40yahoo.com
> 
> This email sent to [EMAIL PROTECTED]


      
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to