how do i remove all subviews from my scrollview...
i have a uiview and a button above it in the scrollview something like this....
here is my code to add sub
The problem with the UIScrollView and others subclass of UIView is that they contains initially some views (like the vertical and horizontal scrollbar for the UIScrollView). So i created a category of UIView to delete the Subviews filtered on the class.
For example:
[UIScrollView removeAllSubviewsOfClass:[FooView class],[BarView class],nil];
The code:
- (void)removeAllSubviewsOfClass:(Class)firstClass, ... NS_REQUIRES_NIL_TERMINATION;
- (void)removeAllSubviewsOfClass:(Class)firstClass, ...
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"FALSEPREDICATE"];
va_list args;
va_start(args, firstClass);
for (Class class = firstClass; class != nil; class = va_arg(args, Class))
{
predicate = [NSCompoundPredicate orPredicateWithSubpredicates:[NSArray arrayWithObjects:predicate,[NSPredicate predicateWithFormat:@"self isKindOfClass:%@",class], nil]];
}
va_end(args);
[[self.subviews filteredArrayUsingPredicate:predicate] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}