views:

393

answers:

3

Does a library exist to work with trees for iPhone ?

+1  A: 

The default way to simulate tree browsing would be with a UINavigationView where the views contain UITableViews containing all the leaf elements of that branch. You may want to look there first in the Apple Documentation. It is quite simple to implement.

If you are intending for something like a Windows Tree View control then I am not aware of any. General concensus suggests that a TV control does not really fit with the iPhone UI paradigm. If you find yourself needing this then maybe you need to rethink your UI design.

I did half an attempt at a tree view, implementing a tableview and using the rowHeightForCellAtIndexPath to return a very small number (0 or 1) for collapsed rows. I had to maintain the tree state in an offline structure (NSDictionary) and render from that. Each cell had to be custom rendered completely. In the end, it was much better to implement it as a Navigation View as this fitted with the iPhone UI and the way you expect iPhone applications to behave much better.

Xetius
+1  A: 

If you are talking about a tree data structure, as opposed to a user interface control, you can use CFTree. A quick summary of how CFTree works is on CocoaDev.com.

Dustin Voss
+2  A: 

Or if you don't want to deal with CoreFoundation objects, SO user Quinn Taylor puts a ton of time into the CHDataStructures framework, which has trees, queues, stacks, etc and that works on Mac and iPhone: http://cocoaheads.byu.edu/code/CHDataStructures

It's a really solid framework and I highly recommend it.

Dave DeLong
I promise I didn't change the text of Dave's answer, I just added a link. :-)
Quinn Taylor