Ven*_*282 5 xcode objective-c subview ios
我正在开发一个应用程序.在那里我获得了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;
for (UIView *subview in subviews) {
NSLog(@"%@", subview);
// List the subviews of subview
[self listSubviewsOfView:subview];
}
}
Run Code Online (Sandbox Code Playgroud)
但我的问题是如何找出该子视图列表中的按钮.请告诉我如何解决这个问题.
Mar*_*lch 16
您可以遍历所有这样的子视图.
for (id subview in subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
//do your code
}
}
Run Code Online (Sandbox Code Playgroud)
迅速
for subview in view.subviews {
if subview is UIButton {
// this is a button
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5191 次 |
| 最近记录: |