I want to list out all the subviews in a UIViewController
. I tried self.view.subviews
, but not all of the subviews are listed out, for instance, the subviews in the UITableViewCell
are not found. Any idea?
You have to recursively iterate the sub views.
- (void)listSubviewsOfView:(UIView *)view {
// Get the subviews of the view
NSArray *subviews = [view subviews];
// Return if there are no subviews
if ([subviews count] == 0) return; // COUNT CHECK LINE
for (UIView *subview in subviews) {
// Do what you want to do with the subview
NSLog(@"%@", subview);
// List the subviews of subview
[self listSubviewsOfView:subview];
}
}
As commented by @Greg Meletic, you can skip the COUNT CHECK LINE above.