Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSButton available only for certain radio button

NSButton available only for certain radio button
Thread Tools
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Aug 8, 2005, 07:16 PM
 
I'm really loving bindings; my app is coming along very nicely with no glue code

Here's one thing I can't figure out how to do yet: I have an NSMatrix of radio buttons, and an NSButton checkbox that I only want made available when a certain radio button is selected. Example:
○ Soup
○ Salad
□ Croutons
Where Croutons would be unavailable unless the user has selected the Salad radio button. I can't figure out how to do this with bindings, as the availability binding on the checkbox requires a BOOL, but an NSMatrix won't give me a BOOL.

Thanks in advance.
     
bewebste
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Aug 9, 2005, 06:02 PM
 
This is kind of a hackish way to do it, but it works as long as there's only one button in the matrix you want this behavior with. You first bind the NSMatrix's selectedTag binding to whatever controller/model object and key you want. If you've been using selectedIndex instead, this means you may need to shuffle around some of your constants and tags of the buttons in the matrix, since it will be the tag of the selected button that gets assigned as the value instead of the index.

Assign the tag value of 0 to the button you want the enabled state of the checkbox to depend on. Then, bind the enabled binding of the checkbox to the same object + key that the matrix's selection is bound to. Once that's done, open the NSValueTransformer pop-up and select NSIsNil. This will mean that the checkbox will be enabled only when the matrix's selected tag is 0, i.e. the checkbox will be enabled only when the button with the 0 tag is selected.

So in your example:

- the tag value for Salad is 0
- selectedTag of the matrix is bound to x.y
- enabled of the Croutons checkbox is bound to x.y with an NSIsNil transformer

This is hackish primarily because NSIsNil is really expecting to get an object as input, but the integer value of a 0 tag is the same as the object value of nil, so it works. To really do this correctly, you would bind the enabled state of the croutons checkbox to another BOOL key in your controller/model that would change its value whenever the key that the matrix is bound to gets changed. Check out +[NSObject setKeys:triggerChangeNotificationsForDependentKey:] to see how to set this dependency up.
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Aug 9, 2005, 10:37 PM
 
I ended up getting it working in a similar way. Thanks.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:47 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,