Reputation: 3301
I have a problem in clearing my view, For a particular case I have been adding user names as label into my view, I may have multiple user based on situation, now my problem is, For one case I want to clear the view without popping it, I am not sure how to remove those added labels, I have an idea I can set tag for each label, and I can clear using that later. Any other efficient way is there in this particular case.
Hope my question is clear thanks.
Upvotes: 0
Views: 327
Reputation: 2907
Call below method and pass the "UIWebView" object as argument:
+(void)removeAllSubViews:(id)pObj
{
NSArray *Array = [pObj subviews];
for(int index = 0; index < [Array count]; index++)
{
[[Array objectAtIndex:index] removeFromSuperview];
}
}
You can also check object like this if you want for any particular object:
if(view isKindOfClass:[UILabel class]) {
//do whatever you want to do
}
Cheers!
Upvotes: 0
Reputation: 3754
Try this:
for (UIView *v in [self.relatedView subviews])
{
[v removeFromSuperview];
}
Upvotes: 0
Reputation: 2312
use this :
for(id viewSub in self.view.subviews)
{
[viewSub removeFromSuperview];
}
this will remove all subviews of View
Upvotes: 0
Reputation: 935
You can do in the following way
for (UIView *view in [self.view subviews])
{
if ([view isKindOfClass:[UILabel class]])
{
[view removeFromSuperview];
}
}
Hope you are asking about this.
Upvotes: 0
Reputation: 4246
use
for (UIView* view in self.view.subviews) {
if(view isKindOfClass:[UILabel class]) {
//do whatever you want to do
}
}
Upvotes: 2
Reputation: 14302
You can remove all subviews like this:
for (UIView *subView in [view subviews])
[subView removeFromSuperview];
Or if you want to access a particular view with tag value of n,
UIView *subview = [view viewWithTag:n]
Upvotes: 0