Hello, How can I loop through all subviews of a UIView, and their subviews and their subviews... Thank you.
views:
795answers:
4
+1
Q:
[IPHONE] How can I loop through all subviews of a UIView, and their subviews and their subviews...
+8
A:
Use recursion:
// UIView+HierarchyLogging.h
@interface UIView (ViewHierarchyLogging)
- (void)logViewHierarchy;
@end
// UIView+HierarchyLogging.m
@implementation UIView (ViewHierarchyLogging)
- (void)logViewHierarchy
{
NSLog(@"%@", self);
for (UIView *subview in self.subviews)
{
[subview logViewHierarchy];
}
}
@end
// In your implementation
[myView logViewHierarchy];
Ole Begemann
2010-04-30 17:41:02
A:
I wrote a category some time back to debug some views.
IIRC, the posted code is the one that worked. If not, it will point you in the right direction. Use at own risk, etc.
TechZen
2010-04-30 17:42:35
+1
A:
The code posted in this answer traverses all windows and all views and all of their subviews. It was used to dump a printout of the view hierarchy to NSLog but you can use it as a basis for any traversal of the view hierarchy. It uses a recursive C function to traverse the view tree.
progrmr
2010-05-01 01:06:34