Skip to content

Instantly share code, notes, and snippets.

@alinradut
Created June 14, 2011 14:27
Show Gist options
  • Select an option

  • Save alinradut/1025002 to your computer and use it in GitHub Desktop.

Select an option

Save alinradut/1025002 to your computer and use it in GitHub Desktop.
Print all subviews with a certain type
- (NSString *)superviewPath:(UIView *)view
{
NSMutableArray *path = [NSMutableArray array];
while (view != nil)
{
[path insertObject:[NSString stringWithFormat:@"(%p) %@",view,NSStringFromClass([view class])] atIndex:0];
view = [view superview];
}
return [path componentsJoinedByString:@" > "];
}
- (void)printSubviewsOfView:(UIView *)view withClass:(Class)class
{
for (UIView *subview in [view subviews])
{
if ([subview isKindOfClass:class])
{
NSLog(@"%@ descendant : %@", NSStringFromClass(class), [self superviewPath:subview]);
}
[self printSubviewsOfView:subview withClass:class];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment