Maulik shah
Maulik shah

Reputation: 1704

how to remove subview from class method in ios?

I have an app.In this app so many class methods used.I want to know is it possible to remove subview from class mehtod?

 +(void)addPregressIndicator:(NSString *)strText view:(UIView *)ShowView
{
    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
    UIView *busyView = [[UIView alloc] initWithFrame:appFrame];
    busyView.backgroundColor = [UIColor clearColor];
    busyView.opaque          = YES;

    UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 95, 95)];

    container.layer.borderWidth     = 5;
    container.layer.cornerRadius    = 10;
    container.layer.borderColor     = [UIColor whiteColor].CGColor;
    [container setBackgroundColor:[UIColor blackColor]];

    UIActivityIndicatorView *av = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    av.center                   = CGPointMake(container.center.x, 34);
    av.hidesWhenStopped         = NO;
    [av startAnimating];

    UILabel *lbl                = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
    lbl.text                    = strText;
    lbl.textAlignment           = NSTextAlignmentCenter;
    lbl.center                  = CGPointMake(container.center.x, 70);
    lbl.textColor               = [UIColor whiteColor];
    lbl.backgroundColor         = [UIColor clearColor];

    [container addSubview:av];
    [container addSubview:lbl];

    container.center = busyView.center;

    [busyView addSubview:container];

    [ShowView addSubview:busyView];



}

+(void)removePregressIndicator:(UIView *)hideView;

{
    // i want remove busyview that subview in viewcontroller.
}

Please help me to remove subivew.

Upvotes: 0

Views: 352

Answers (3)

Chirag Kalsariya
Chirag Kalsariya

Reputation: 256

+ (void)removePregressIndicator:(UIView *)hideView;
{
    UIView *progView=[self.view viewWithTag:YourTag];
    [progView removeFromSuperview];
}

Upvotes: 0

Nishant Gupta
Nishant Gupta

Reputation: 457

Assigne tag to a each view and access the view with tag and put it

+(void)removePregressIndicator:(UIView *)hideView;

{
      UIView *viewToRemove = [self.view viewWithTag:assigne_tag];
     [viewToRemove removeFromSuperview];
}

Upvotes: 0

LorenzOliveto
LorenzOliveto

Reputation: 7936

You can set a unique tag for the busyView like this busyView.tag = your unique tag;

And then you can remove the view with this code

+(void)removePregressIndicator:(UIView *)hideView;
{
    UIView *busyView = [hideView viewWithTag:your unique tag];
    if (busyView){
        [busyView removeFromSuperview];
    }
}

You should make sure that the busyView tag is unique for all the subviews of hideView.

Upvotes: 1

Related Questions