IPhone: how to remove all objects from UIScrollView

Basically, I want to remove all objects from UIScrollView, and I have not yet found a solution for it, because the simple "removeAllObjects" command does not work. Does anyone have an idea how to do this?

+5
source share
4 answers

Even simpler:

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

The easiest way:

for(UIView *subview in [scrollView subviews]) {

    [subview removeFromSuperview];

}
+9
source

:

, .

:

#define XPScrollViewSubviewStartTag             100

for(NSInteger = 0;i<[viewArray count];i++){
     UIView* view = [viewArray objectAtIndex:i];
     view.tag = XPScrollViewSubviewStartTag + i;
     [scrollView addSubview:view];
}

,

for(UIView* view in [scrollView subviews]){
      if(view.tag >= XPScrollViewSubviewStartTag)
           [view removeFromSuperview];
}

UIView

for(id view in [scrollView subviews]){
      if(![view isKindOfClass:[CustomView class]])
            continue;

      //not necessary, but just to make things understandable
      CustomView* customView = (CustomView*)view;
      [customView removeFromSuperview];
}
+3

Oritm , , , scrollview. , , . , scrollview UILabels, , :

// This will remove the scrollview but the scrollbars will remain 
for (UIView *subview in [self.detailsExpander.scrollView subviews]) {
    if ([NSStringFromClass([subview class]) isEqualToString:@"UILabel"])
        [subview removeFromSuperview];
}

, ( ). . , , , .

+1

All Articles