Re: Getting an NSOutlineView Item's parent
Re: Getting an NSOutlineView Item's parent
- Subject: Re: Getting an NSOutlineView Item's parent
- From: Scott Stevenson <email@hidden>
- Date: Wed, 18 Oct 2006 13:59:46 -0700
On Oct 18, 2006, at 4:13 AM, The Beerbowers wrote:
My problem is that when the data source
method outlineView:objectValueForTableColumn:byItem: is called, I
need to be able to get a pointer to the item's parent
Create a simple NSObject subclass and use that instead of arrays,
dictionaries, etc. The subclass can have a weak reference to its
parent.
I'm not sure if I understand what your saying here. Maybe I didn't
explain my problem very well either? Just in case here's an example:
The data source's method outlineView:outlineView
objectValueForTableColumn:tableColumn byItem:item is called. From
this method I need to get a pointer to 'item's parent in the
NSOutlineView. That is my entire problem. (Sorry for being so
cryptic before.)
You're trying to solve this via the NSOutlineView side of things, but
that's not very Cocoa-like. It's generally much cleaner for the items
*inside the view* to know who their parent is.
It's sounds like you're just using Foundation classes in the view at
the moment (dictionaries, arrays, strings), but it would probably be
easier to make a custom class which contains the dictionaries and
arrays.
In that case, your NSOutlineView would be populated with instances of
a class called Group:
@interface Group : NSObject {
NSString *title;
NSMutableSet *children;
Group *parent;
}
@end
And the setter for parent would look like this:
- (void)setParent:(id)newParent
{
// weak reference
parent = newParent;
}
Then in objectValueForTableColumn:tableColumnbyItem:item you say:
id parent = [item parent];
The children in the NSMutableSet (or maybe NSMutableArray) could be
whatever class you want. I don't know the design of your app so this
is just a starting point.
- Scott
_______________________________________________
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