你们中的任何人都知道如何在视图中获取子视图列表?有一种方法可以将列表放入数组中吗?
NSMutableArray *subviews= .... //all my subviews
答案 0 :(得分: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];
}
}
请浏览此链接How to list out all the subviews in a uiviewcontroller in iOS?