ios如何在视图中获取子视图列表?

Jua*_*uan -2 xcode subview uiview ios

你们中的任何人都知道如何在视图中获取子视图列表?有一种方法可以将列表放入数组中吗?

NSMutableArray *subviews= .... //all my subviews
Run Code Online (Sandbox Code Playgroud)

Sau*_*kla 10

你可以这样做

- (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;

    for (UIView *subview in subviews) {

        NSLog(@"%@", subview);

        // List the subviews of subview
        [self listSubviewsOfView:subview];
    }
}
Run Code Online (Sandbox Code Playgroud)

请浏览此链接如何在iOS中的uiviewcontroller中列出所有子视图?