• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting an NSOutlineView Item's parent
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Re: Getting an NSOutlineView Item's parent
      • From: Perrog <email@hidden>
References: 
 >Re: Cocoa-dev Digest, Vol 3, Issue 1261 (From: The Beerbowers <email@hidden>)

  • Prev by Date: Re: Re: Getting an NSOutlineView Item's parent
  • Next by Date: Display application specific global hot-key in Keyboard Shortcuts preferences?
  • Previous by thread: Re: Cocoa-dev Digest, Vol 3, Issue 1261
  • Next by thread: Re: Re: Getting an NSOutlineView Item's parent
  • Index(es):
    • Date
    • Thread