如何正确设置启用 NSSegmentedControl

发布于 2024-10-01 16:40:58 字数 526 浏览 8 评论 0原文

我希望我的 NSSegmentedControl 在启用时选择一个分段,在禁用时不选择任何分段(iTunes 中的视图 NSSegmentedControl 具有的行为类型)。

这里有一些图片:

imagebam.com 启用并选择

imagebam.com 正确禁用

imagebam.com 禁用但不正确

(*)我认识到我可以编写一个函数,每当 BOOL 属性更改时调用,在这个函数中,我可以设置所有被分割的段或选择适当的段,但我想知道是否有一种方法通过 Cocoa Bindings 或 Interface Builder 来完成此操作。

更新:添加了一些问题的图像

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤凫 2024-10-08 16:40:58

编辑:我对此并不完全确定,但我认为“无选择占位符”是您最好的选择。 http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CocoaBindingsRef/Concepts/BindingsOptions.html%23//apple_ref/doc/uid/20002304-187525

我仍然认为当您有条件地禁用该控件时,您必须以编程方式指定不进行任何选择。

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.

方觉久 2024-10-08 16:40:58

编程解决方案可以是这样的:

- (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;
     }
}

我只是为与 viewSegment 绑定的 BOOL 属性 segmentEnabled 实现自己的设置器

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文