从UIScrollView中删除子视图

时间:2011-02-26 02:11:53

标签: iphone cocoa-touch ios uikit uiscrollview

我需要从subviews中移除图片ScrollView,我尝试从array subviews删除,但这是NSArray不可变的。

如何从subview的{​​{1}}移除scrollviews array

6 个答案:

答案 0 :(得分:35)

    NSArray *viewsToRemove = [scrollView subviews];
    for (UIView *v in viewsToRemove) [v removeFromSuperview];

答案 1 :(得分:12)

你可以这样做,

[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

答案 2 :(得分:5)

这将删除UIScrollView的所有子视图,但其滚动指示符:     _scrollView.showsHorizo​​ntalScrollIndicator =     _scrollView.showsVerticalScrollIndicator = NO;     [_scrollView.subviews makeObjectsPerformSelector:@ selector(removeFromSuperview)];     _scrollView.showsHorizo​​ntalScrollIndicator =     _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()
}