0

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 Commented Jul 25, 2012 at 15:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.