On Mar 18, 2011, at 10:14 PM, Ken Thomases wrote:

> On Mar 18, 2011, at 3:45 AM, Christian Ziegler wrote:
> 
>> I'm having hard times figuring out how to bind an NSMatrix properly. I got 
>> an NSMatrix with NSButtonCells (checkboxes) and I want to somehow bind to my 
>> model which of these checkboxes are selected. What should work is binding 
>> the content objects of the NSMatrix to an ArrayController and fill the 
>> arrayController's content with NSButtonCells programmatically.
> 
> Huh?  An NSMatrix is a view (in the Model-View-Controller design pattern), an 
> array controller is a controller, and it provides access to model data.  
> NSButtonCells are not model data, they are elements of the view.  You don't 
> "fill the arrayController's content with NSButtonCells".

Hehe shame on me!

> 
> You should have a model property somewhere which is an array of objects to be 
> presented in the matrix.  This might be as simple as strings for the names of 
> the checkboxes, or it might be objects each of which has a property which 
> will be the name of a checkbox.  You bind the array controller's contentArray 
> to this model property (the array of objects).
> 
> You then bind the matrix's content to the array controller's arrangedObjects. 
>  If the objects are not themselves the values for the checkboxes, you also 
> bind the matrix's contentValues to the array controller's arrangedObjects 
> with a model key path which obtains the values for the checkboxes.
> 
> You can bind the matrix's selectedObjects or selectedValues to another 
> controller's property, which is a to-many property with the appropriate 
> mutation accessors.  You bind selectedObjects if you want to track the 
> objects which correspond to each checkbox.  You bind selectedValues if you 
> want to track the values, if there's a distinction (see previous paragraph).
> 
> It should also work to bind the matrix's selectedObjects to the array 
> controller's selection.  Then you can bind the array controller's 
> selectionIndexes to a property of your coordinating controller (e.g. File's 
> Owner).  That way, your property which tracks the selection can be related 
> back to the property which provided the array controller's content, instead 
> of merely being another array which shares some elements.
> 
> I hope that helps.
> 
> Regards,
> Ken
> 

Thanks Ken. I was assuming that it works that way, however I figured there must 
be an easier way. I will write a nice little model object then :)

Cheers,
Chris

_______________________________________________

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 arch...@mail-archive.com

Reply via email to