Last active
August 29, 2015 14:16
-
-
Save kmdarshan/02b0b662eb2e1012777d to your computer and use it in GitHub Desktop.
Recursively printing all subviews within a view given a tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)printSubViews:(UIView *)view withTag:(NSInteger)tag | |
{ | |
if (view == nil) { | |
return; | |
} | |
if ( [view tag] == tag) { | |
NSLog(@"%@", view); | |
return; | |
} | |
for (UIView *subview in [view subviews]) | |
{ | |
[self printSubViews:subview withTag:tag]; | |
} | |
} | |
-(void) findAllViews { | |
UIView *baseView = [UIView new]; | |
[baseView setTag:1]; | |
UIView *secondRowA = [UIView new]; | |
[secondRowA setTag:2]; | |
UIView *secondRowB = [UIView new]; | |
[secondRowB setTag:3]; | |
UIView *thirdRowA = [UIView new]; | |
[thirdRowA setTag:4]; | |
UIView *thirdRowB = [UIView new]; | |
[thirdRowB setTag:5]; | |
[secondRowA addSubview:thirdRowA]; | |
[secondRowB addSubview:thirdRowB]; | |
[baseView addSubview:secondRowA]; | |
[baseView addSubview:secondRowB]; | |
[self printSubViews:baseView withTag:6]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment