How can I remove all child subviews of a certain class type from a parent UIView?
You can use my useful function.
/** Remove all subviews of a type from container View.
@param class Type of subviews to remove.
@param ownerMainView UIView container.
@see showAllSubviewsOf:
@see hideAllSubviewsOf:
@see getAllSubviewsOfClass:fromView:
*/
+ (void)removeAllSubviewsOfClass:(Class)class fromView:(UIView *)ownerMainView {
if (!ownerMainView) { return; }
for (NSInteger i=[ownerMainView.subviews count] - 1; i>=0; i--) {
if ([[ownerMainView.subviews objectAtIndex:i] isKindOfClass:class]) {
[[ownerMainView.subviews objectAtIndex:i] removeFromSuperview];
}
}
}
Download the ready-for-use source file (.m) of Remove all UIView subviews filtered by a Class
No comments:
Post a Comment