Note that there are some explanatory texts on larger screens.

plurals
  1. POTraversing the View Hierarchy on the iPhone
    text
    copied!<p>Here is a helpful routine you can use on the iPhone to traverse the view hierarchy when you want to know what's being created and where it's going. </p> <p>This routine dumps the view hierarchy to NSLog starting at the view passed in. Subviews show their index in the subviews array and all super classes in order separated by a colon with the frame size at the end. </p> <p>To dump the entire view hierarchy of your application, call the method like this:</p> <pre><code>dumpViews([[UIApplication sharedApplication] keyWindow], @"", @""); </code></pre> <p>To display the hierarchy of the the camera view, override this method in your controller:</p> <pre><code>navigationController:willShowViewController:viewController:animated </code></pre> <p>and call the dump routine like this:</p> <pre><code>dumpViews(self.modalViewController.view, @"", @""); </code></pre> <p>For all other views:</p> <pre><code>dumpViews(myView, @"", @""); </code></pre> <p><br /> </p> <h2>Source</h2> <pre><code>void dumpViews(UIView* view, NSString *text, NSString *indent) { Class cl = [view class]; NSString *classDescription = [cl description]; while ([cl superclass]) { cl = [cl superclass]; classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]]; } if ([text compare:@""] == NSOrderedSame) NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame)); else NSLog(@"%@ %@ %@", text, classDescription, NSStringFromCGRect(view.frame)); for (NSUInteger i = 0; i &lt; [view.subviews count]; i++) { UIView *subView = [view.subviews objectAtIndex:i]; NSString *newIndent = [[NSString alloc] initWithFormat:@" %@", indent]; NSString *msg = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i]; dumpViews(subView, msg, newIndent); [msg release]; [newIndent release]; } } </code></pre> <p><br /><br> <br /> </p> <h2>Example Camera Dump</h2> <pre> UIView:UIResponder:NSObject {{0, 0}, {320, 480}} 0: PLCameraView:UIView:UIResponder:NSObject {{0, 0}, {320, 480}} 0: UIView:UIResponder:NSObject {{0, 0}, {320, 427}} 1: UIImageView:UIView:UIResponder:NSObject {{10000, 10000}, {320, 480}} 2: UIView:UIResponder:NSObject {{0, 427}, {320, 53}} 3: PLCropOverlay:UIView:UIResponder:NSObject {{0, 0}, {320, 480}} 0: UIImageView:UIView:UIResponder:NSObject {{0, 20}, {320, 96}} 1: PLCropLCDLayer:UIView:UIResponder:NSObject {{0, 20}, {320, 96}} 2: TPBottomDualButtonBar:TPBottomButtonBar:TPBottomBar:UIView:UIResponder:NSObject {{0, 384}, {320, 96}} 0: TPPushButton:UIThreePartButton:UIPushButton:UIControl:UIView:UIResponder:NSObject {{22, 26}, {128, 47}} 1: TPCameraPushButton:TPPushButton:UIThreePartButton:UIPushButton:UIControl:UIView:UIResponder:NSObject {{170, 26}, {128, 47}} 0: UIImageView:UIView:UIResponder:NSObject {{51, 12}, {26, 19}} </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload