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:
enabled and selected disabled correctly disabled but not correctly(*) I reco开发者_如何学Cgnize 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
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.
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
精彩评论