1
votes

I have an NSArrayController configured with mode 'Entity' that contains Core-Data-Entities of the type 'Person' and 'Prepares Content' selected. All other properties are the default-ones. As expected, this arraycontroller updates its arrangedObjects as i create new Person-entities (via a button-click):

-(IBAction)addEntity:(id)sender{
  Person* new = [NSEntityDescription insertNewObjectForEntityForName:@"Person"
                           inManagedObjectContext:[self managedObjectContext]];
  new.text = @"text";
  new.date = [NSDate date];
}

I have bound the content of a view-based NSTableView to the 'arrangedObjects'-property of this arrayController, to display the Persons. In one column i have an editable (but otherwise default) NSTextField bound to the 'objectValue.text' property of the TableCellView.

If i edit the 'text'-property within the table and add another person (while the tablecell is still in edit-mode) the table loses focus, editing is ended and the new person is shown in the table. Everything looks fine.

However if i want to add another person, the arrayController does not update the arrangedObjects-property (i found that setContent: of the arrayController is not called anymore).

Is this intended behaviour?

2

2 Answers

5
votes

I found the answer myself. I noticed that no NSManagedObjectContextObjectsDidChangeNotifications were sent after i edited the table (as they did before).

This link pointed me in the right direction. After i modified my addEntity-method in the following way, everything worked as expected:

-(IBAction)addEintrag:(id)sender {
 Person* new = [NSEntityDescription insertNewObjectForEntityForName:@"Person" 
                          inManagedObjectContext:[self managedObjectContext]];
 new.name = @"test";
 new.datum = [NSDate date];
 [self.managedObjectContext processPendingChanges];
}
0
votes

If you want your arrayController to automatically rearrange objects, check the "Auto Rearrange Content" checkbox on your arrayController in Interface Builder or use setAutomaticallyRearrangesObjects: programmatically.