【发布时间】:2013-02-03 07:26:18
【问题描述】:
你们中的任何人都知道如何获取视图中的子视图列表吗?有没有办法将列表放入数组中?
NSMutableArray *subviews= .... //all my subviews
【问题讨论】:
-
您应该阅读手册...UIView Class reference 有答案
你们中的任何人都知道如何获取视图中的子视图列表吗?有没有办法将列表放入数组中?
NSMutableArray *subviews= .... //all my subviews
【问题讨论】:
你可以这样做
- (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?
【讨论】: