Re: checkbox grouping with binding
Re: checkbox grouping with binding
- Subject: Re: checkbox grouping with binding
- From: Ricky Sharp <email@hidden>
- Date: Sat, 10 Dec 2005 17:57:25 -0600
On Dec 10, 2005, at 3:37 PM, Herbert wrote:
I have a group of checkboxes, and one is the master and the others
belong to it as a group, i.e.:
master
one
two
three
etc.
I would like to have the master tri-state so that if any of the
subbuttons are checked it goes into tri-state mode, and if all are
selected it's selected.
Also natch I would like the subbuttons to take their lead from the
master - if it's checked, all of the subbuttons should be checked.
I know I can write some code to do this but can it be done with
bindings?
I think you'll have to write code either way (if using bindings,
you'd need a model).
It also seems that if using bindings, you may have a circular
dependency. Let's assume that you set up dependent keys via
setKeys:triggerChangeNotificationsForDependentKey:. When you
interact with the master checkbox, the 'masterState' attribute of
your model is changed. And, since you'd probably set
'childOneState', 'childTwoState', etc. as dependent keys, they would
change. But, 'masterState' would also be a dependent key of the
child state keys. I've never set up such a circular dependency, so
don't know what would happen.
Assuming that would all work, I think you could use the following
accessors for masterState. Note that masterState would not be an
ivar of your model, it would always get its value from the children.
- (void)setMasterState:(int)newState
{
if newState is ON then set all children states to ON
else set all children states to OFF
}
- (int)masterState
{
if all children states are ON then return ON
else if all children states are OFF then return OFF
else return MIXED
}
Accessors for each child state (of which you'd have an ivar in the
model)...
- (void)setChild1State:(int)newState
{
child1State = newState;
}
- (int)child1State
{
return child1State;
}
It may be the case where doing things via action methods may be simpler.
___________________________________________________________
Ricky A. Sharp
mailto:email@hidden
Instant Interactive(tm)
http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden