开发者

How to properly set an NSSegmentedControl enabled

开发者 https://www.devze.com 2023-01-24 16:20 出处:网络
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).

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:

How to properly set an NSSegmentedControl enabled

enabled and selected

How to properly set an NSSegmentedControl enabled

disabled correctly

How to properly set an NSSegmentedControl enabled

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号