2

I am pretty new for cocoa programming. I am learning binding, trying to make a simple binding code as:

    - (void)awakeFromNib
    {
        self.aValue = [[Model alloc] init];


        NSString *aKey = @"value";
        NSDictionary *aDic = [[NSDictionary alloc] initWithObjectsAndKeys:self.aValue, aKey, nil];

        self.anObjctCtrler = [[NSObjectController alloc] initWithContent:nil];
        [self.anObjctCtrler setContent:aDic];
        NSLog(@"%ld", [[[[self.anObjctCtrler content] valueForKey:@"value"] number] integerValue]);
     }

The anObjectCtrler is an NSObjectController in the Interface Builder, and I "bind" a NSTextField to Object Controller, the class of anObjectCtrler, at a model key path of "value" and controller key of "selection"; the Obeject Controller has referencing outlet to File's Owner as anObeject.

When I run the codes, the NSTextField displays "No Selection", not as expected as the value of "self.aValue". You can see I check the content of the object controller by using an output of "NSLog...", it shows the correct value.

Anyone can help me to solve this, please?

Many Thanks.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
Herodazhu
  • 21
  • 1
  • same problem here. It drives me crazy - all binding questions are only answered for tables, but absolutely nothing on simple binding of text-field to a dictionary entry. – Motti Shneor Apr 04 '16 at 06:38
  • You are creating new object controller in code and not using reference from interface builder. You are facing issue where awakefrom nib has already been called but the content of object controller is still empty. – Marek H Jan 23 '17 at 11:33

0 Answers0