开发者

Is it possible to bind together controls, AppDelegate and UserDefaults codeless?

I have an AppDelegate like this:

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

@end

I will use boundValue for some real-time calculations later inside AppDelegate. In main .xib I also have NSTextField control.

开发者_Python百科

So now I'd like to bind both NSTextField and UserDefaults.boundValue key to my AppDelegate.boundValue. And of course I'd like to do that with minimal code writing.

I have found the way how to bind NSTextField either to AppDelegate or to UserDefaults. But how can I bind AppDelegate to UserDefaults? How to wire these three pieces — control + delegate + defaults — together without additional lines of code?


You'll need a little bit of extra code:

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

Now you can connect in IB as you wish, provided of course appDelegate and userDefaults are represented in main.xib by those green and blue cubes.

Edit: Here's quite a nice tutorial on binding user preferences: Binding your preferences in Cocoa

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜