모든 하위 뷰를 UIViewController. 시도 self.view.subviews했지만 모든 하위보기가 나열 UITableViewCell되지 않았습니다. 예를 들어의 하위보기를 찾을 수 없습니다. 어떤 생각?
답변
하위 뷰를 재귀 적으로 반복해야합니다.
- (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];
    }
}
@Greg Meletic이 언급했듯이 위의 COUNT CHECK LINE을 건너 뛸 수 있습니다.
답변
보기 계층 구조를 덤프하는 xcode / gdb 기본 제공 방법이 유용합니다-recursiveDescription, http://developer.apple.com/library/ios/#technotes/tn2239/_index.html
유용 할 수있는보다 완전한 뷰 계층 구조를 출력합니다.
> po [_myToolbar recursiveDescription]
<UIToolbarButton: 0xd866040; frame = (152 0; 15 44); opaque = NO; layer = <CALayer: 0xd864230>>
   | <UISwappableImageView: 0xd8660f0; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xd86a160>>
답변
Swift의 우아한 재귀 솔루션 :
extension UIView {
    func subviewsRecursive() -> [UIView] {
        return subviews + subviews.flatMap { $0.subviewsRecursive() }
    }
}
모든 UIView에서 subviewsRecursive ()를 호출 할 수 있습니다.
let allSubviews = self.view.subviewsRecursive()
답변
재귀 적으로 인쇄해야합니다.이 방법은 뷰의 깊이를 기반으로 탭도 표시합니다.
-(void) printAllChildrenOfView:(UIView*) node depth:(int) d
{
    //Tabs are just for formatting
    NSString *tabs = @"";
    for (int i = 0; i < d; i++)
    {
        tabs = [tabs stringByAppendingFormat:@"\t"];
    }
    NSLog(@"%@%@", tabs, node);
    d++; //Increment the depth
    for (UIView *child in node.subviews)
    {
        [self printAllChildrenOfView:child depth:d];
    }
}
답변
다음은 빠른 버전입니다.
 func listSubviewsOfView(view:UIView){
    // Get the subviews of the view
    var subviews = view.subviews
    // Return if there are no subviews
    if subviews.count == 0 {
        return
    }
    for subview : AnyObject in subviews{
        // Do what you want to do with the subview
        println(subview)
        // List the subviews of subview
        listSubviewsOfView(subview as UIView)
    }
}
답변
나는 파티에 조금 늦었지만 좀 더 일반적인 해결책 :
@implementation UIView (childViews)
- (NSArray*) allSubviews {
    __block NSArray* allSubviews = [NSArray arrayWithObject:self];
    [self.subviews enumerateObjectsUsingBlock:^( UIView* view, NSUInteger idx, BOOL*stop) {
        allSubviews = [allSubviews arrayByAddingObjectsFromArray:[view allSubviews]];
                   }];
        return allSubviews;
    }
@end
답변
원하는 모든 것이 UIViews 배열 인 경우 이것은 하나의 라이너 솔루션입니다 ( Swift 4+ ).
extension UIView {
  var allSubviews: [UIView] {
    return self.subviews.reduce([UIView]()) { $0 + [$1] + $1.allSubviews }
  }
}
