rano
rano

Reputation: 5676

How to properly set an NSSegmentedControl enabled

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

Upvotes: 1

Views: 1475

Answers (2)

rano
rano

Reputation: 5676

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

Upvotes: 0

griotspeak
griotspeak

Reputation: 13247

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.

Upvotes: 0

Related Questions