Curnelious
Curnelious

Reputation: 1

Cant remove subview from a view?

I am trying to remove the indicator subview from a UIView , but it removes both of them and not only the subview .

My views are :

 UIView * aView = [[UIView alloc] initWithFrame:CGRectMake(0.5*winSize.width-winSize.width/3, 0.85*winSize.height , winSize.width/1.5, winSize.width/8)];
    aView.backgroundColor = [UIColor clearColor];
    aView.tag  = 31000;
    UIActivityIndicatorView  *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
    av.frame=aView.bounds;
    [av setBackgroundColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:0.85]];
    av.layer.cornerRadius=4;
    av.tag = 31001;
    [aView addSubview:av];
    [[[CCDirector sharedDirector]view]addSubview:aView];
    [av startAnimating];

and I have tried to remove it with many methods i have found here :

 UIActivityIndicatorView *tmpimg = (UIActivityIndicatorView *)[[[CCDirector sharedDirector]view] viewWithTag:31001];
    if(tmpimg)
        [((UIView *)tmpimg) removeFromSuperview];

or

   UIView *removeView;
    while((removeView = [[[CCDirector sharedDirector]view] viewWithTag:31001]) != nil)
    {
        [removeView removeFromSuperview];
    }

or

 UIView * aView = [[[CCDirector sharedDirector]view] viewWithTag:31000];
    if(aView)
        for(UIView *subview in [aView subviews])
            [subview removeFromSuperview];

but it always removes both of them ...I am lost ..

Upvotes: 0

Views: 724

Answers (1)

peko
peko

Reputation: 11335

this will remove any UIActivityIndicatorView from your view, without any need of tagging it what is imo a bad solution

for (UIView *aSubView in aView) {
    if ([aSubView isKindOfClass:[UIActivityIndicatorView class]])
        [aSubView removeFromSuperview];
}

Upvotes: 3

Related Questions