Posted By

phifty on 08/11/09


Tagged

objc debugging UIView


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

umang_nine
unravelme1
stationstops
avanadra
rvachere
sb
nsbuckner
synced
miamk
Tintenklecks
cnathan


UIView and Subviews Exploded


 / Published in: Objective C
 

This is adapted from Erica Sadun's explode code in her book "iPhone Developer's Cookbook". It takes any UIView-based element and exposes all of the subviews and their subviews, etc. Its a good way to dig into UIKit elements as well as debug your own UIView-based code. In code, always set level to zero.

  1. #define objectString(anObject) [[anObject description] UTF8String]
  2.  
  3. #import <Foundation/Foundation.h>
  4. @interface Util : NSObject {}
  5. + (void)explode:(id)viewObj level:(int)level;
  6. @end
  7.  
  8. @implementation Util
  9. + (void)explode:(id)viewObj level:(int)level
  10. {
  11. // indent to show the current level
  12. for (int i = 0; i < level; i++) {
  13. printf("-", level);
  14. }
  15.  
  16. // show the class and superclass for the current object
  17. printf("%s : ", objectString([viewObj class]));
  18. id obj = [viewObj superclass];
  19.  
  20. while (NULL != obj) {
  21. printf("%s : ", objectString([obj class]));
  22. obj = [obj superclass];
  23. }
  24.  
  25. printf("\n");
  26.  
  27. // recurse for all subviews
  28. for (UIView *sub in [viewObj subviews]) {
  29. [Util explode:sub level:(level + 1)];
  30. }
  31. }
  32. @end

Report this snippet  

You need to login to post a comment.