Archive for November, 2009

Exploring iPhone view hierarchies

Friday, November 20th, 2009

Sometimes it’s useful to quickly see all the subviews of an iPhone view.

Perhaps you’re debugging a problem in one of your views or trying to understand the inner workings of one of the built in views.

You can simply iterate over a view’s subviews, but then you won’t see subviews deeper than one level. You need a method that recursively walks the hierarchy.

Luckily Apple has already done this with an undocumented UIDebugging category on UIView that makes this very easy: recursiveDescription

At the gdb prompt in the Xcode debugger you can say:

p [[self view] recursiveDescription]

and instantly see a description of the entire view hierarchy.

Follow us on Twitter