Re: programmatically adding model objects to NSOultineView/NSTreeController
Re: programmatically adding model objects to NSOultineView/NSTreeController
- Subject: Re: programmatically adding model objects to NSOultineView/NSTreeController
- From: Ken Victor <email@hidden>
- Date: Sat, 9 Jun 2007 14:31:55 -0700
mmalc,
thanx for the response.
At 7:40 PM -0700 6/8/07, mmalc Crawford wrote:
On Jun 8, 2007, at 6:18 PM, Ken Victor wrote:
i've got an NSOutlineView bound to an NSTreeController. if i
programmatically add a new child object to one of the nodes, it
works fine and displays only if the parent of the new child already
had other children. however, if i add a child to a node that didn't
previosly have any children, it is not showing up.
How are you adding the new child?
1) in response to user interaction, i will create my "real" object
(ie, non NSProxy); this posts a notification about the creation of
the new object
2) my window controller (for the window containing the outline view),
responds to this notification and calls rearrangeObjects for the tree
controller for the outline view
3) the tree controller calls my isLeaf method of the proxy object
(which represents the parent of the newly created real object)
4) my (proxy's) isLeaf method checks to see if its known children
(proxy objects) contains a proxy for the newly created object. if not
and if the newly created real object should be shown, i then create a
new proxy object (for the new real object) and link it in to my model
tree (which is composed of my proxy objects)
5) my isLeaf object (from 3 above) will then return appropriately
based on whether or not it now contains any children
then i've tried various combinations of:
expanding the item for the parent proxy item
reloadItem
reloadItem:reloadChildren:
insertObject:atArrangedObjectIndexPath:
(using the indexPath of the parent, the indexPath of
the parent with appended index of 0 or 1)
addChild:
insertChild:
reloadData
setNeedsDisplay:
rearrangeObjects:
all to no avail. as previsously mentioned, there is no problem if the
parent for the new object already contains children; there is only a
problem when the new object is the first child. note also that if i
close the outline window and then reopen it, thus recreating
everything, the new child shows up properly.
Apart from that, the proxy object should be KVC compliant.
perhaps, but the following:
[self willChangeValueForKey: @"filteredChildren"];
generates the following compile time warning:
warning: 'KVOutlineObjectProxy' may not respond to
'-willChangeValueForKey:'
and trying
[self performSelector: @selector(willChangeValueForKey:)
withObject: @"filteredChildren"];
doesn't seem to help any
my model objects are actually instances of NSProxy
I suspect not.
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSProxy_Class/Reference/Reference.html>
thanx for the pointer. i can't tell you how many times i've read
this! :-) and i just reread to make sure i wasn't missing anything.
note: nowhere does this say whether or not NSProxy implements any of
the KVO/KVC protocols
thanx,
ken
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden