RE: Binding a unique-selection checkbox in a table view?
RE: Binding a unique-selection checkbox in a table view?
- Subject: RE: Binding a unique-selection checkbox in a table view?
- From: Lee Ann Rucker <email@hidden>
- Date: Sun, 23 Nov 2014 06:58:36 +0000
- Thread-topic: Binding a unique-selection checkbox in a table view?
If your data model allows for Jobs knowing about the active job, I think it'll work to bind the checkbox to something like this:
-(BOOL)isActiveJob
{
self.dataModel.activeJob == self;
}
and use keyPathsForValuesAffectingValueForKey: to trigger updates to isActiveJob when dataModel.activeJob changes. You could probably even have the setter do
- (void)setIsActiveJob: (BOOL)flat
{
if (flag) self.dataModel.activeJob = self;
else self.dataModel.activeJob = nil;
}
assuming you can have no active job, otherwise IBAction would work better, but then you probably want radio style instead of checkbox.
________________________________________
From: cocoa-dev-bounces+lrucker=email@hidden [cocoa-dev-bounces+lrucker=email@hidden] on behalf of Rick Mann [email@hidden]
Sent: Saturday, November 22, 2014 12:42 PM
To: Jerry Krinock
Cc: Cocoa Developers
Subject: Re: Binding a unique-selection checkbox in a table view?
> On Nov 22, 2014, at 03:17 , Jerry Krinock <email@hidden> wrote:
>
>
>> On 2014 Nov 21, at 19:09, Rick Mann <email@hidden> wrote:
>>
>> In an OS X app I have an NSTableView that binds to an array of Job objects. I'd like to have a checkbox column that the user can check that indicates the "active" job. There should be only one of these. Is there a way to bind the value of that column to something other than the Job for that row, to handle this?
>
> This uniqueness of the “active” job seems to me like it belongs in your data model, not your view controller.
It is in the data model. But it's currently smelly. When the active property gets set, that entity checks with the AppDelegate (it could be any object) to see who the currently-active instance was, and unsets that one. I don't like having my model know about the AppDelegate, but I don't see a way to bind to something else directly and say "if I am the same as this other thing, then check the widget. If the widget gets checked, make me the active thing on this other thing."
>
> If this is a quickie project, implementing the uniqueness in an IBAction method, as discussed yesterday, is a quick fix that will work.
>
> But for long-term projects that might in the future support, say, other views or scripting, Cocoa Bindings can be used to provide a more disciplined model-view-controller separation. Cocoa Bindings do have a development cost, quite a bit of baggage, but you’re already using Cocoa Bindings in this project anyhow.
>
>
> _______________________________________________
>
> 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:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.apple.com_mailman_options_cocoa-2Ddev_rmann-2540latencyzero.com&d=AAIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=ie7S-J__EKnfyVOBV7-jV2rZ--p47O6vkyTklpDM3h4&m=YIT0V7qqh7xHCN5Hjjq0fjBBkqmg_EXm8cXLbH1FAgI&s=8jYlUl_djmI15be3j9eh3ra4B70-5r1bUJCj7RwfPVY&e=
>
> This email sent to email@hidden
--
Rick Mann
email@hidden
_______________________________________________
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:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.apple.com_mailman_options_cocoa-2Ddev_lrucker-2540vmware.com&d=AAIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=ie7S-J__EKnfyVOBV7-jV2rZ--p47O6vkyTklpDM3h4&m=YIT0V7qqh7xHCN5Hjjq0fjBBkqmg_EXm8cXLbH1FAgI&s=5gQaJJkz5Azmp7j08XVftwyPZMXguYKXBIl8jWWQIxg&e=
This email sent to email@hidden
_______________________________________________
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