Search code examples
cocoacore-datacocoa-bindingsmagicalrecord

Binding an NSTreeController with MagicalRecord


I'm trying to use MagicalRecord in an OSX app. I have an NSOutlineView with the following hierarchy:

Group
- Customer
-- Project

A group is automatically created when the app is run for the first time. Everything is setup via bindings and the thing basically works. The only problem I have is that on the first run of the app when there is no data yet I see the automatically created group but newly created customers within the group will only show up when I close and restart the app. From then on everything works fine.

Somehow the NSTreeController is not notified about changes in the relationships. I tried displaying the relationships using tableviews and everything shows up here.

Is there any sample code that shows how to use MagicalRecord with an NSTreeController / NSOutlineView?


Solution

  • I seem to have fixed the problem. The reason inserted customers did not show up had something to do with the outline view's delegate. After removing my implementation of -outlineView:isGroupItem; the items suddenly showed up in the tree.

    It is still not perfect because the group items don't expand automatically and the user does not see if there are children items contained within (I hide the disclosure triangle for groups). But as a workaround I immediately select newly inserted items in the NSTreeController which expands any parent groups.