UIView and Subviews Exploded


/ Published in: Objective C
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.