Controlling bindings with code

Christiaan Hofman cmhofman at gmail.com
Tue Mar 25 15:58:38 PDT 2008


On 25 Mar 2008, at 9:15 PM, Trent Jacobs wrote:

> The app I'm writing is centered around a particular list of objects  
> (for example a list of items in a shop) with various filters  
> allowed. it's a core data app and I'm using bindings wherever  
> possible.
>
> In the model I'm using I have an entity for my objects and I've set  
> up relationships to the entities I'll be filtering on (for example  
> brand, colour, whatever).
>
> I've got everything with perfectly when I hook up the bindings in  
> IB, i.e. when I select a brand the list of objects is filtered to  
> only show objects of the selected brand. However, when I try to do  
> the bindings in code it doesn't work.
>
> To create the bindings I use:
>
> 		[myObjectController bind : @"contentSet"
> 					   toObject : filterController
> 					withKeyPath : @"selection.objects"
> 						options : nil];
>
> where myObjectController and filterController are NSArrayController  
> objects and selection.objects represents the relationship in the  
> model.
>
> This works fine. However, when I remove the contentset binding I  
> would expect the filtering to be removed.

Why? The -unbind: method does not trigger a reload, - 
bind:toObject:withKeyPath:options: however does. This does make sense  
to me.

> This doesn't happen. What happens is that the list of objects stays  
> the same although the controlling relationship to the filtering  
> array controller is gone, i.e. I change brands and the list stays  
> constant. To remove the bindings I am simply using:
>
> 		[myObjectController unbind : @"contentSet"];
>
> I think this is happening because the NSArrayController is not being  
> told to refresh but i can't find how to force a refresh.
>

-rearrangeObjects could do it. Or binding to some other property.

> Any ideas?
>
> Thanks!

Why aren't you just using filter predicates?

Christiaan



More information about the MacOSX-dev mailing list