-1

I hope many of us have same problem of binding to work, specially nested binding.

Scenario :

I have a class Person, with name and role properties. Roles will come from other source.

Person Class:

@interface Person : NSObject
@property (strong) NSString *fullName;
@property (strong) NSString *role;
@end

AppDelegate Class:

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

@property (strong) NSArray *persons;
@property (strong) NSArray *roles;
- (IBAction)save:(id)sender;

@end

I have a tableview and a popup button. TableView is bind-ed to ArrayController.

How to bind popupbutton to roles, so that the selected value is updated in objects or Person, i.e. our model ?

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • If you using a view based Table, I (and others) had problems with binding to a NSPopup Button within a Tableview [Shown Here](http://stackoverflow.com/questions/10768492/how-to-populate-nspopupbutton-from-coredata-in-view-based-nstableview), also I found this [link](http://stackoverflow.com/questions/7937280/whats-the-difference-between-content-values-and-content-objects) very useful. – Cory Jun 17 '13 at 22:33

1 Answers1

2

The AppDelegate.m :

@implementation AppDelegate

- (id)init
{
    self = [super init];
    if (self) {
        self.roles=@[@"Admin",@"SuperUser",@"Clerk",@"Associate",@"Poen"];

        Person *p1=[Person new];
        [p1 setFullName:@"Anoop"];

        Person *p2=[Person new];
        [p2 setFullName:@"Billy"];

        Person *p3=[Person new];
        [p3 setFullName:@"Steven"];

        self.persons=@[p1, p2, p3];
    }
    return self;
}



- (IBAction)save:(id)sender {

    for (Person *p in self.persons) {
        NSLog(@"Name : %@",p.fullName);
        NSLog(@"role : %@",p.role);
    }
}

And the binding goes like this :

enter image description here

enter image description here

enter image description here

enter image description here

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140