• 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: Yet another NSOutlineView question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yet another NSOutlineView question...


  • Subject: Re: Yet another NSOutlineView question...
  • From: Julian Barkway <email@hidden>
  • Date: Sat, 16 Mar 2002 06:56:04 +0100

On Friday, March 15, 2002, at 11:34 pm, Itrat Khan wrote:

On Friday, March 15, 2002, at 04:43 PM, email@hidden wrote:

I've set up an NSOutlineView which I've finally got working to my satisfaction - apart from one thing. How can I easily convert the index returned from the underlying TableView's selectedRow method into an index I can use to access a source array that might be deeply nested in a hierarchy that could belong to any of a number of root items, any or all of which might be expanded or not as the case may be? This sort of thing is trivial in an ordinary table view but a total nightmare when outlines are involved.


It's easiest if each item in your model maintains an inverse relationship to its container, such as a file item does for its containing directory. You could then use [NSOutlineView's itemAtRow:selectedRow] to get the selected object and therefore its container.

But this is exactly my problem. As I understand it, itemAtRow: merely returns the way item is portrayed in the view (in this case, as an instance of NSString) not the object itself. Obviously, I could do a search of my array for the string in question but, until I can relate the row returned by selectedRow to a specific array in my hierarchy of nested arrays, that isn't going to work.

The problem still remains: how do I relate the selectedRow to a data item in any one of a number of arrays? Obviously, one answer would be to somehow enumerate the view's internal structure and figure it out that way but there aren't any methods for doing this that I can see. Or I could traverse my own hierarchy and ask if an item is currently expanded or not and then search each array as required.... I could then use rowForItem: to make sure I've got the right one.... Hmmmmmmm. Maybe this is the answer. I'll get back to you..... :-D

If your data source is a flat array, consider wrapping it in a tree class that explicitly defines the hierarchical relationships and use that tree as your data source. There may be other solutions depending on what you're trying to model.

Regards,
Itrat.

..................................................................
Itrat Khan
Modeless Software, Inc.
http://www.modeless.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Yet another NSOutlineView question... (From: Itrat Khan <email@hidden>)

  • Prev by Date: Re: Leak in NSData +dataWithContentsOfURL:
  • Next by Date: Re: dd: speed up mouse with Cocoa?
  • Previous by thread: Re: Yet another NSOutlineView question...
  • Next by thread: Re: Yet another NSOutlineView question...
  • Index(es):
    • Date
    • Thread