How do I inspect the view hierarchy in iOS?
Xcode 6 now has 3D view hierarchy inspection built in like Reveal App and Spark Inspector.
Click on the "Debug View Hierarchy" button while your app is running to pause execution and inspect the views at the current moment.
More info at Apple's documentation.
I need to inspect the view hierarchy on an iPhone program
Along the lines of what Yannick suggests, Erica Sadun has code here that pretty-prints the view hierarchy (with class and frame information). You can make this into a UIView category with the following interface:
@interface UIView (ExploreViews)
void doLog(int level, id formatstring,...)
for (i = 0; i < level; i++) printf(" ");
id outstring = [[NSString alloc] initWithFormat:formatstring arguments:arglist];
fprintf(stderr, "%s\n", [outstring UTF8String]);
@implementation UIView (ExploreViews)
doLog(level, @"%@", [[self class] description]);
doLog(level, @"%@", NSStringFromCGRect([self frame]));
for (UIView *subview in [self subviews])
[subview exploreViewAtLevel:(level + 1)];
How to find views in Debug View Hierarchy based on their address?
If you type (or copy/paste) the hex address into the search field at the bottom of the Navigator Pane, it should filter / find the object:
Is there a way to see object names in debug view hierarchy?
No, there is not (unfortunately).
The information is not maintained at runtime to my knowledge, so you also won't be able to use lldb from Xcode's console to figure it out.
Probably worth a feature request to Apple!
View Debugging: What are the layers of view in any View Controller?
The Xcode debugger provides the ability to inspect and understand the view hierarchy.
With your app running in the debugger, click the Debug View Hierarchy button in the debug bar.
Here is reference of visual code debugging.
Xcode Debug View Hierarchy finding viewcontroller
Update: Starting with Xcode 9, view controllers are listed right along the view hierarchy in the visual debugger.
You can get the memory address of the selected view from the inspector in Xcode and then use the console to get the view's view controller using
UIView implements this method by returning the UIViewController object
that manages it (if it has one) or its superview (if it doesn’t)