An NSObjectController constraint associated with a class property. Help!

I teach myself cocoa and enjoy the experience most of the time. I tried my best every day with the simple problem that Google failed. I read Cocoa Bindings Topics and I think I will delay it, but still cannot solve my problem.

I have a very simple MTSong class that has various properties. I used @synthesize to create getter / seters and can use KVC to change properties. In my application controller, the following works:

mySong = [[MTSong alloc]init];
[mySong setValue:@"2" forKey:@"version"];

In case I do something in my MTSong.h code class:

#import <Foundation/Foundation.h>

@interface MTSong : NSObject {
    NSNumber    *version;
    NSString    *name;
}
@property(readwrite, assign) NSNumber *version;
@property(readwrite, assign) NSString *name;
@end

and MTSong.m:

#import "MTSong.h"

@implementation MTSong

- (id)init
{
    [super init];
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

@synthesize version;
@synthesize name;
@end

In Interface Builder, I have a label (NSTextField) that I want to update whenever I use KVC to change the version of a song. I do the following:

  • NSObjectController doc Inspector- > Attributes I:

    • :
    • : MTSong
    • version, -
  • Inspector- > Bindings- > Content Control

    • : ( , ...)
    • :
  • Inspector

    • : Object Controller
    • : mySong
    • :

2 "mySong", , . .


mySong, AppController.h :

#import <Cocoa/Cocoa.h>
@class MTSong;

@interface AppController : NSObject {
    IBOutlet NSButton *start;
    IBOutlet NSTextField *tf;
    MTSong *mySong;
}
-(IBAction)convertFile:(id)sender;
@end

, , , AppController, 2:

  1. Inspector- > Bindings- >
    • : App Controller
    • : mySong

3.

  1. Inspector
    • : Object Controller
    • :
    • :

!

+3
1

mySong, . , , , , - mySong File Owner ( ).

+1

Source: https://habr.com/ru/post/1732095/


All Articles