如何在iOS的uiviewcontroller中列出所有子视图? [英] How to list out all the subviews in a uiviewcontroller in iOS?

查看:21
本文介绍了如何在iOS的uiviewcontroller中列出所有子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想列出 UIViewController 中的所有子视图.我试过self.view.subviews,但是并不是所有的子视图都列出来了,比如没有找到UITableViewCell中的子视图.有什么想法吗?

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

    for (UIView *subview in subviews) {
        
        // Do what you want to do with the subview
        NSLog(@"%@", subview);

        // List the subviews of subview
        [self listSubviewsOfView:subview];
    }
}

这篇关于如何在iOS的uiviewcontroller中列出所有子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆