バインディングを理解し始めたら、誰かが答えてくれるといいのですが、非常に簡単な質問があります。プログラムでNSString値を変更し、バインディングを介してNSTextFieldをその値に更新したいと思います。NSTextFieldとNSLabelがあります。myStringの値を適切に変更することを表すために、NSButtonがあります。
- NSTextFieldの値をAppDelegateのmyStringプロパティにバインドし、[継続的に値を更新]をオンにしました。
- NSLabelの値をAppDelegateのmyStringプロパティにバインドしています。
- NSButtonアウトレットをsetDefaultメソッドに接続しています。
NSTextFieldと入力すると、NSLabelは期待どおりに更新されますが、ボタンをクリックすると、myStringプロパティは更新されますが、NSTextFieldでは更新されません。
NSTextFieldをmyStringプロパティに更新するにはどうすればよいですか????
AppDelegate.h
@interface AppDelegate : NSObject<NSApplicationDelegate>
{
NSString *myString;
}
@property (assign) IBOutlet NSWindow *window;
@property NSString *myString;
- (IBAction)setDefault:(id)sender;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize window = _window;
@synthesize myString;
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
myString = @"This is a string";
}
- (IBAction)setDefault:(id)sender
{
NSLog(@"%@", myString);
myString = @"This is a string";
NSLog(@"%@", myString);
}
@end