我需要从subviews
中移除图片ScrollView
,我尝试从array
subviews
删除,但这是NSArray
不可变的。
如何从subview
的{{1}}移除scrollviews array
?
答案 0 :(得分:35)
NSArray *viewsToRemove = [scrollView subviews];
for (UIView *v in viewsToRemove) [v removeFromSuperview];
答案 1 :(得分:12)
你可以这样做,
[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
答案 2 :(得分:5)
这将删除UIScrollView的所有子视图,但其滚动指示符: _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; [_scrollView.subviews makeObjectsPerformSelector:@ selector(removeFromSuperview)]; _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = YES;
答案 3 :(得分:2)
for (UIView *v in [scrollView subviews]) {
[v removeFromSuperview];
}
答案 4 :(得分:1)
在子视图上调用-removeFromSuperview。
答案 5 :(得分:1)
夫特
for subview in scrollView.subviews {
subview.removeFromSuperview()
}