Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically update a TableView that is governed by Cocoa Bindings
    text
    copied!<p>I'm fairly new to obj-c and cocoa so please bear with me:</p> <p>I have a NSTableView set up with cocoa bindings which works as expected with the simple -add -remove, etc methods provided by an instance of NSArrayController in my nib. I would like to programmatically add objects to the array that provides content for this controller (and hence for the table view) and then update the view accordingly.</p> <p>I current have a working method for adding a new object to the array (verified by NSLog) but I can't figure out how to update the table view.</p> <p>So: <strong>How do I update the bound tableview?</strong> (ie, after I have programmatically added objects to my array). <strong>I'm essentially after some view refreshing code like [view reloadData] in glue code, but I want it to work with the bindings I have in place.</strong></p> <p>Or is there a KVC/KVO related solution to this problem?</p> <p>Code Details: AppController.h</p> <pre><code>@interface AppController : NSObject @property NSMutableArray *clientsArray; -(IBAction)addClientFooFooey:(id)sender; @end </code></pre> <p>AppController.m (note, I also have the appropriate init method not shown here)</p> <pre><code>@implementation AppController ... -(IBAction)addClientFooFooey:(id)sender{ [self.clientsArray addObject:[[Client alloc] initWithFirstName: @"Foo" andLastName:@"Fooey"]]; //Need some code to update NSTableView here } @end </code></pre> <p>Client.h just simply defines two properties: firstName and lastName. The 2 columns of an NSTableView in my mainmenu.nib file are appropriately bound to these properties via an array controller bound to my AppController instance.</p> <p>On a side note/as an alternative. How could I add functionality to the existing NSArrayController method -add, ie, something like: -addWithFirstName:andLastName and still have this compatible with bindings?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload