开发者

addChild, etc. using NSTreeController and NSTreeNode (snow leopard)

I have a setup with an object (OTNodeDatum) (OT for OutlineTest) to be the represented object in NSTreeNode. NSTreeNode is the Class shown in the attribut开发者_运维技巧es page for NSTreeController.

I have document based app, no core data. On MyDocument init, I set up content with an NSMutableArray containing one item, an NSTreeNode with a represented object which contains a single property (yes, name).

Add button, Add Child button, Delete button, hooked up via interface builder to the NSTreeController add action, etc.

It works up to a point.

When I do an add, I get a new blank line which I can edit, but the inserted text goes away when I leave the cell.

When I do a delete, things get deleted.

When I do add child, nothing happens.

I think I have to subclass either NSTreeNode, or NSTreeController to get the right behavior in terms of adding children and adding a new represented object in addition to adding a new tree node.

IS this on the right track? If I subclass NSTreeController would I just override the add, addChild, to get the right thing to happen? And what could I mess up? I can't seem to find any guidance on this, although I've spent a long time looking.

Thanks.

John V


It appears that the right way to do things, or at least, a way, is to use

-(void)insertObject:(id)object atArrangedOjectIndexPath:(int)index;

First create representedObject, create a new NSTreeNode with that represented object, then insert it. More work than a simply connecting the add button to the tree controller, but (hopefully) the advantages of using NSTreeNode make up for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜