• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Radio button group and binding "enabled" of other GUI elements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Radio button group and binding "enabled" of other GUI elements


  • Subject: Re: Radio button group and binding "enabled" of other GUI elements
  • From: Kaspar Fischer <email@hidden>
  • Date: Fri, 23 Sep 2005 19:24:05 +0200


On 23.09.2005, at 15:25, Ricky Sharp wrote:
Using value transformers is a valid approach.

You could also set up dependent keys. In your controller, create an accessor for radioIndex and bind the selected index of your radio group to that. Then create three getters: isASelected through isCSelected and bind the enabled state of your text fields to that. Their implementation would be like:

-(BOOL)isASelected
{
    return [[self radioIndex] == 0];
}

Finally, in your controller's +initialize, set up dependent keys so that when radioIndex changes, your three "isSelected" attributes will be changed accordingly.

Finally, something else to consider is to just hide your text fields when not in use. You could then use a borderless, tabless, transparent tabview (3 tabs; one for each text field). Then simply bind the radio group's selected index to the tab view's tab index.

Hi Ricky,

Thanks for your answer, especially for the trick with the tabview.
I like it because I am not forced to write code (which forces me
to separate the GUI into IB stuff and code).

For the sake of completeness, here is my current implementation
based on value transformers; it required me to do some coding,
but it should be fairly resuable. Comments and suggestions for
other solutions very welcome, of course!

// file IsEqualTo.h
#import <Cocoa/Cocoa.h>

@interface IsEqualTo : NSValueTransformer
{
    NSArray *_values;
    BOOL _handleNilAsYes;
}

- (id)initWithConstant:(id)constant
      returnsYesForNil:(BOOL)returnsYesForNil;
- (id)initWithConstants:(NSArray *)constants
       returnsYesForNil:(BOOL)returnsYesForNil;

@end

// file IsEqualTo.m
#import "IsEqualTo.h"

@implementation IsEqualTo

+ (Class)transformedValueClass
{
    return [NSNumber self];
}

+ (BOOL)allowsReverseTransformation
{
    return NO;
}

- (id)initWithConstant:(id)constant
      returnsYesForNil:(BOOL)returnsYesForNil
{
    self = [super init];
    if (self != nil) {
        _values = [[NSArray arrayWithObject:constant] retain];
        _handleNilAsYes = returnsYesForNil;
    }
    return self;
}

- (id)initWithConstants:(NSArray *)constants
       returnsYesForNil:(BOOL)returnsYesForNil
{
    self = [super init];
    if (self != nil) {
        _values = [constants retain];
        _handleNilAsYes = returnsYesForNil;
    }
    return self;
}

- (id)transformedValue:(id)value
// Returns true if and only if value equals one of the constants in _values
// or is nil and the instance was initialized with returnsYesForNil equal to YES.
{
NSEnumerator *enumerator = [_values objectEnumerator];
id constant;
BOOL result = NO;
if (value == nil)
result = _handleNilAsYes;
else
while (constant = [enumerator nextObject])
if ([constant isEqual:value]) {
result = YES;
break;
}
return [NSNumber numberWithBool:result];
}


@end

You then bind the GUI elements as described in the "P.S." of
the original post.

Kaspar
_______________________________________________
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


References: 
 >Radio button group and binding "enabled" of other GUI elements (From: Kaspar Fischer <email@hidden>)
 >Re: Radio button group and binding "enabled" of other GUI elements (From: Ricky Sharp <email@hidden>)

  • Prev by Date: zip compression/decompression SDK
  • Next by Date: Re: zip compression/decompression SDK
  • Previous by thread: Re: Radio button group and binding "enabled" of other GUI elements
  • Next by thread: Re: Radio button group and binding "enabled" of other GUI elements
  • Index(es):
    • Date
    • Thread