【发布时间】:2024-05-04 11:05:02
【问题描述】:
而不是单独removeFromSubview 为我要删除的每一件事,我想知道是否有什么东西可以从超级视图中删除所有内容。
【问题讨论】:
标签: ios cocoa-touch ios7
而不是单独removeFromSubview 为我要删除的每一件事,我想知道是否有什么东西可以从超级视图中删除所有内容。
【问题讨论】:
标签: ios cocoa-touch ios7
我正在为此使用类别方法
@interface UIView (Additions)
- (void)removeAllSubviews
@end
@implementation UIView (Additions)
- (void)removeAllSubviews
{
for (UIView *subview in self.subviews)
[subview removeFromSuperview];
}
@end
所以你可以打电话
[self.superview removeAllSubviews];
从超级视图中删除所有内容。
【讨论】:
for(UIView *view in self.superview.subviews)
{
[view removeFromSuperview];
}
但请注意这一点,它可以删除您不知道的 Apple 内置插件,从而改变视图与用户交互的方式。
【讨论】:
一个班轮
[viewYouWantToRemoveFrom.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
【讨论】: