1

I'm instantiating an NSTreeController programmatically and want to put it into entity mode, but regardless of what I do it sticks to class mode.

The following code fragment doesn't work:

    NSTreeController *treeCon       = [[NSTreeController alloc] initWithContent:nil];
    treeCon.entityName              = currentEntityItem.entityDescription.name;
    XaDocument *document            = self.document;
    treeCon.managedObjectContext    = document.managedObjectContext;
    treeCon.objectClass             = nil;

Does anyone know how to programmatically put an NSObjectController into entity mode? (I do know how to do this using IB, but I need to instantiate the controller programmatically.)

Mojo66
  • 1,109
  • 12
  • 21
  • See [NSArrayController initialization](https://stackoverflow.com/a/1862665/4244136) – Willeke Nov 12 '19 at 14:22
  • @Willeke Thanks for the link, but adding a fetch doesn't change anything. – Mojo66 Nov 12 '19 at 18:40
  • Set `automaticallyPreparesContent` to `YES`? – Willeke Nov 12 '19 at 22:01
  • It looks like a bug to me, `initWithCoder` sets a `isUsingManagedProxy` flag. I don't know if the missing flag causes any issues. How do you check if `treeCon` is in entity mode? The description in the debugger says class mode but the content looks ok. – Willeke Nov 13 '19 at 03:01
  • I check `arrangedObjects`. – Mojo66 Nov 13 '19 at 11:42
  • Is `arrangedObjects` something like `<_NSControllerTreeProxy: 0x60c00008b680>, child nodes {}`? Try `treeCon.arrangedObjects.childNodes` or `treeCon.content`. – Willeke Nov 13 '19 at 11:53

0 Answers0