1

I'd like to have my NSSegmentedControl with a segment selected when enabled and with no segment selected while disabled (the kind of behavior that the view NSSegmentedControl in iTunes has).

Here some images:

imagebam.com enabled and selected

imagebam.com disabled correctly

imagebam.com disabled but not correctly

(*) I recognize that I could write a function to call whenever the BOOL property changes and in this function I could set all the segments desected or select the appropriate one, BUT I'd like to know if there's a way to accomplish this through Cocoa Bindings or Interface Builder.

UPDATE: added some images of the problem

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
rano
  • 5,616
  • 4
  • 40
  • 66

2 Answers2

0

EDIT: I am not completely sure about this, but i think 'No Selection Placeholder' is your best bet. http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CocoaBindingsRef/Concepts/BindingsOptions.html%23//apple_ref/doc/uid/20002304-187525

I still think you would have to programmatically specify no selection when you conditionally disable the control though.

griotspeak
  • 13,022
  • 13
  • 43
  • 54
0

The programmatic solution can be something like this:

- (void)setSegmentEnabled:(BOOL)enabled{
     if (enabled)
     {
         int vState = [[NSUserDefaults standardUserDefaults] integerForKey:@"SelectedSegmentView"];
         [viewSegment setSelectedSegment:vState];
         segmentEnabled = YES;        
     }
     else
     {
         [viewSegment setSelected:NO forSegment:0];
         [viewSegment setSelected:NO forSegment:1];
         [viewSegment setSelected:NO forSegment:2];
         segmentEnabled = NO;
     }
}

I'm just implementing my own setter for the BOOL property segmentEnabled which is being binded with the viewSegment

rano
  • 5,616
  • 4
  • 40
  • 66