Re: NSMatrix of NSButtonCells prototype bindings not applied to instances in matrix
Re: NSMatrix of NSButtonCells prototype bindings not applied to instances in matrix
- Subject: Re: NSMatrix of NSButtonCells prototype bindings not applied to instances in matrix
- From: Ron Lue-Sang <email@hidden>
- Date: Mon, 13 Apr 2009 17:46:46 -0700
On Apr 6, 2009, at 19:35 , Ben Golding wrote:
I've been trying to create a calendar matrix of days which are
clickable to select a day in the month. It's a something of a
classic example of using NSMatrix from what I've read but I'm trying
to use bindings to hook it up.
I am using an NSArrayController holding an array of NSButtonCell's
which is connected as the NSMatrix's content. I set the bindings on
the NSMatrix's NSButtonCell prototype connecting the target to my
controller object (to select the day) and also the enabled attribute
to the NSButtonCell's isEnabled attribute.
The NSArrayController is populated with NSButtonCell's that I create
with the correct date placement, etc, using copies of NSMatrix's
prototype.
Sounds like you're trying to put view level objects into your array
controller. Bindings don't work that way.
You should just be able to bind the matrix (I'm guessing you're using
checkboxes) to an arrayController full of *model* objects. These
objects can represent the days in the month and whether the day is
selected.
Then the matrix…
- contents come from the arrayController.arrangedObjects. This way,
the number of button cells in the matrix will be determined by the
number of Day objects in your arrayController.
- contentValues are from the arrayController's arrangedObjects.name.
These will provide the titles for the button cells. Again, this is
based on the Day model objects in your arrayController.
- selectedObjects is the array of model objects that were selected
in the matrix by checking the day's checkbox button. You'll want to
bind this property to some object that wants to find out which days
the user chose. Maybe you have a viewController? With a read/write
property like selectedDays? Then bind the matrix' selectedObjects
binding to yourViewControllerInstanceInYourNibWhichMightBeFile'sOwner
with the keypath selectedDays.
Hope that helps…
When the app runs, the bindings on the button cell instances in the
matrix don't seem to be observed, that is, button presses aren't
forwarded to the target and the enabled attribute is ignored. If I
set the bindings on the button cells within the NSMatrix directly
(ie, not using the protoype), they are observed.
I don't quite get what I'm doing wrong. Should I be creating my
array of button cells using something other than copy to pick up the
bindings? Should I be asking the array controller to create the
button cell instances? Is there something that's not working in the
NSMatrix prototype? Or am I misunderstanding some concept?
Thanks,
Ben.
_______________________________________________
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