Rather than individually removeFromSubview for each thing I want to remove, I'd like to know if there's something which removes everything from the superview.
            Asked
            
        
        
            Active
            
        
            Viewed 112 times
        
    0
            
            
        
        Mike Mertsock
        
- 11,825
 - 7
 - 42
 - 75
 
        user3316549
        
- 23
 - 5
 
3 Answers
0
            
            
        I am using category method for this
@interface UIView (Additions)
- (void)removeAllSubviews
@end
@implementation UIView (Additions)
- (void)removeAllSubviews
{
    for (UIView *subview in self.subviews)
        [subview removeFromSuperview];
}
@end
So you can call
[self.superview removeAllSubviews];
to remove everything from superview.
        Avt
        
- 16,927
 - 4
 - 52
 - 72
 
- 
                    You should always use a prefix for category methods – Paul.s Feb 17 '14 at 20:36
 
0
            
            
        for(UIView *view in self.superview.subviews)
{
    [view removeFromSuperview];
}
Be careful with this though, it can remove Apple built-ins that you don't know are there and thereby change the way the view interacts with the user.
        Putz1103
        
- 6,211
 - 1
 - 18
 - 25
 
0
            
            
        One liner
[viewYouWantToRemoveFrom.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        Paul.s
        
- 38,494
 - 5
 - 70
 - 88