Re: NSOutlineView, NSTreeController and itemForPersistentObject...
Re: NSOutlineView, NSTreeController and itemForPersistentObject...
- Subject: Re: NSOutlineView, NSTreeController and itemForPersistentObject...
- From: Scott Ahten <email@hidden>
- Date: Sun, 8 May 2005 23:39:45 -0400
Keith,
I'm not quite sure what you're trying to accomplish here..
When using an outline view with bindings and core data, the tree
controller bound to your outline view provides the data, not the
datasource delegate. Since the default NSManagedObject
implementation does not have attributes to store the state of outline
view's nodes (if the node is expanded, if the node has children, if
it is a leaf node, etc.), this information is stored in a
NSArrayControllerTreeNode object that is wrapped around your
NSManagedObject or subclass.
If you're trying to read or restore the expanded or unexpanded state
of an outline view's nodes, you'll need to walk each node in the
outline view, get the corresponding persistent object using
observedObject, then query or set the nodes state by calling the
appropriate outline view methods with the node, such as
isItemExpanded:item, collapseItem:item, expandItem:item, etc.
Since NSOutlineView is a subclass of NSTableView, you can use
numberOfRows and itemAtRow:index methods to walk the outline view and
access it's nodes. You can either create an attribute to store this
state in your persistent object or store it externally.
Note: Each Core Data persistent object has an built-in read-only
"objectID" attribute that can be use to uniquely identify each
object. You can use this ID as a key to externally store the state of
each object node in your outline view.
- Scott
On May 7, 2005, at 1:06 PM, Keith Blount wrote:
Hello,
I'm running into yet more problems with
NSTreeController... It seems that this class is only
half-finished, but maybe I am wrong. The problem is
that when you use bindings with an NSOutlineView using
NSTreeController, the delegate and datasource methods
do not have direct access to the items held by
NSTreeController, which seems like madness to me...
For instance, if you hook up a datasource to an
NSOutlineView that uses bindings (eg. the one in the
OutlineEdit Core Data example) and then try to use a
datasource method such as
outlineView:persistentObjectForItem:, you will find
that the "item" object passed in is not the actual
object, but a proxy object of class
_NSArrayControllerTreeNode.
When I was experiencing a similar problem a few days
ago, Scott Stevenson on this list very helpfully
pointed out that the only way he knew around this was
to use an undocumented method, -observedObject.
Calling this on the item passed into outline view
datasource and delegate methods does indeed retrieve
the object.
However, I am now trying to get my outline view to
save its state using the datasource methods, and
whilst I can use -observedObject to get a persistent
object in outlineView:persistentObjectForItem:, there
is no way to use this information to restore things in
outlineView:itemForPersistentObject:, because
NSTreeController will expect this to return an object
of type _NSArrayControllerTreeNode - a private API
class.
It seems insane that using Core Data and bindings with
an outline view would prevent you from using any of
the useful datasource or delegate methods that call
for direct access to the item, but I cannot find
anything to solve this.
If anybody has delved into this, I would be very
grateful for some pointers.
Many thanks in advance,
Keith
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40pixelfreak.net
This email sent to email@hidden
- - -
:: email@hidden
:: http://www.pixelfreak.net
- - -
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden