简体   繁体   English

将NSTextField的Enabled属性绑定到BOOL属性

[英]Binding NSTextField's Enabled property to a BOOL property

I am a Mac dev newbie. 我是Mac开发新手。 I have a dialog with some set of controls. 我有一个带有一些控件的对话框。 The controls needs to be enabled/disabled based on a radio selection. 需要根据无线电选择启用/禁用控件。 The way I did it is by creating IBOutlet variables for each of these controls and then calling control's SetEnabled() when the radio selection changes. 我这样做的方法是为每个控件创建IBOutlet变量,然后在单选更改时调用控件的SetEnabled()。 It all works fine but now there are 8 IBOutlet variables and then 8 statements to set their state. 一切正常,但是现在有8个IBOutlet变量,然后有8个语句来设置它们的状态。 Wondering if there is a nice way to do it through binding? 想知道是否有通过绑定实现此目标的方法吗?

I declared a BOOL property typeOneEnabled and set the NSTextField's Enabled binding to File Owner >> typeOneEnabled. 我声明了BOOL属性typeOneEnabled ,并将NSTextField的Enabled绑定设置为File Owner >> typeOneEnabled。 Thought it would change the enabled state when the property changes but that does not seem to work. 以为它会在属性更改时更改启用状态,但这似乎不起作用。 Am I missing something here or its not possible? 我在这里错过什么还是不可能吗?

// in header I have  
BOOL typeOneEnabled;  
@property BOOL typeOneEnabled;

// in mm file  
@synthesize typeOneEnabled

// then to change the property val in a method  
self.typeOneEnabled = someval;

I remember putting some code immediately before and after setting the property value but it did not work and I reverted it. 我记得在设置属性值之前和之后都放了一些代码,但是它没有用,我还原了它。 Was something related to WithKey:@"typeOnEnabled". 与WithKey:@“ typeOnEnabled”有关。

If the enabled binding is used for NSTextField and related make sure the bound BOOL property is always accessed through the KVO accessors by using the setter method or the dot syntax. 如果NSTextField enabled绑定用于NSTextField和相关的绑定,请确保始终使用setter方法或点语法通过KVO访问器访问绑定的BOOL属性。 Also make sure that if the 'NSTextField' value is also bound to a property, that the value binding does disable Conditionally Sets Editable . 还要确保如果“ NSTextField”值也绑定到属性,则该值绑定不会禁用“ Conditionally Sets Editable Otherwise this leads to enabling of the control. 否则,这将导致启用控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM