是否可以将控件,AppDelegate和UserDefaults无代码绑定在一起?

时间:2011-07-04 14:54:25

标签: cocoa cocoa-bindings

我有AppDelegate这样:

@interface AppDelegate : NSObject <NSApplicationDelegate> {
    NSString *boundValue;
}
@property (nonatomic, retain) NSString *boundValue;

@end

稍后我会在boundValue内使用AppDelegate进行一些实时计算。在主.xib我也有NSTextField控件。

所以现在我想将NSTextFieldUserDefaults.boundValue键绑定到我的AppDelegate.boundValue。当然,我想用最少的代码编写来做到这一点。

我找到了如何将NSTextField绑定到AppDelegateUserDefaults的方法。但是如何将AppDelegate绑定到UserDefaults?如何连接这三个部分 - 控制+委托+默认 - 一起没有额外的代码行?

1 个答案:

答案 0 :(得分:0)

您需要一些额外的代码:

@property (nonatomic, retain) IBOutlet NSString *boundValue;

现在您可以根据需要在IB中进行连接,当然,前提是appDelegate和userDefaults在main.xib中由绿色和蓝色立方体表示。

编辑: 这是一个关于绑定用户首选项的非常好的教程:Binding your preferences in Cocoa

相关问题