Reputation: 1
I have the following scenario in a NSoutlineView
:
ParentObject [checkbox]
- ChildObject 1 [checkbox]
- ChildObject 2 [checkbox]
Each checkbox has a binding set up to a bool value of the respective object in a NSTreeController
. When a user selects the parentObject checkbox, the respective children checkboxes should also be set. However, when a child object checkbox is set, the parent checkbox should not be affected. I cannot seem to get the parent functionality working properly.
My current attempted solution to the problem is: when the checkbox is set call:
-(IBAction)CheckSelected:(NSButtonCell *)sender
{
// Somehow access the cells bound object in the NSTreeController ?????
}
However from my research I have not been able to find a way to get access to the cell's respective object in the NSTreeController
.
Any insight on the problem would be greatly appreciated. I feel like this is a common problem that people would run into using an NStreeController and I am curious if I am taking the proper approach.
Thanks :)
Upvotes: 0
Views: 346
Reputation: 9553
The checkboxes shouldn’t be set up to call an action—they should be bound to a property, like, say, “isChecked”.
In your ParentObject you’ll have code similar to:
- (void)setIsChecked:(BOOL)isChecked;
{
_isChecked = isChecked;
for (ChildObject *childObject in self.children)
childObject.isChecked = isChecked;
}
Since the children’s checkboxes are also bound, the children’s new state will be reflected in the outline view immediately.
Upvotes: 1