0
votes

In my MainController, there's a persons array, which binds to a NSArrayController. The persons's name are displayed in a table name column. If I bind a button to NSArrayController add method, I can add the button to add a new person, but if add the new person in method, the the tabel doesn't show the new person, I don't know why.

enter image description here

my code to add new person

Person *p =[[Person alloc]init];
[self.persons addObject:p];

UPDATE: I know the answer by http://chanson.livejournal.com/85659.html because NSMutableArray addObject isn't KVC, so I need to use

  [[self mutableArrayValueForKey:@"persons"] addObject:person];
1
is persons the name of the array, the array controller, or both? It looks like it's both from what you posted - rdelmar

1 Answers

1
votes

If self.persons in the line [self.persons addObject:p] is referring to the array, then you need to add the line self.persons = persons; after it to have the table be updated. I've never been quite sure why this is necessary, presumably, it has to do with KVO.

If, on the other hand, self.persons refers to the array controller, then it should work as you have it written, since adding an object to the array controller is adding it to its arranged objects, which the table column is bound to. Doing it that way also updates the array, since it is bound to the array controller.