Re: NSMatrix bindings
Re: NSMatrix bindings
- Subject: Re: NSMatrix bindings
- From: Christian Ziegler <email@hidden>
- Date: Thu, 24 Mar 2011 08:51:55 +0100
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".
>
> 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
>
Hi,
so I tried it the way Ken described it. However if I start the app, the Matrix is empty. I created the Matrix and all Cells with their titles in IB, assuming that these objects will be created after the nib was loaded. The arrayControllers class type is set to NSString.
Other checkboxes (NSButtons) in my GUI which I set to "On" in IB are also "Off" after starting the app, so it seems that values set in IB are not being set on the model as an initial value. Can anybody confirm that or am I doing something wrong?
Cheers,
Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden