0

I am stuck in hidden problem. I want to remove all UIProgressView from Superview. I am creating cross button in this way,

crossButton = [[CCMenuItemImage alloc] initWithNormalSprite:[CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"close-bttn.png"]] selectedSprite:nil disabledSprite:nil block:^(id sender)
                                     {
                                         [self hideProgressBarForDownload];
                                         [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationInAppLayerClosed object:self userInfo:nil];
                                         [[GameManager sharedGameManager]setCurrentLayer:-1];
                                         [self removeFromParentAndCleanup:YES];
                                     }];

While when it is clicked, following methods are call in a hierachy

-(void) hideProgressBarForDownload
{
    [[DownloadManager sharedDownloadManager]removeAllProgressbarsIfvisible];
}

-(void)removeAllProgressbarsIfvisible
{
    NSArray * allkeys = [currentDownloads allKeys];

    for (int i = 0; i < [allkeys count]; i++)
    {
        NSString *key = [allkeys objectAtIndex:i];
        DownloadItem * item = [currentDownloads valueForKey:key];
        UIProgressView * progress = item.progressIndicator;
        //progress.hidden = YES;
        if (progress.superview)
        {
            [progress removeFromSuperview];
        }
    }
 }

I guess every piece of code is right but don't know why they are not removing.

Thanks in advance.

Hammy
  • 35
  • 1
  • 5
  • remove the if(progress.superview) and see if it works? – hariszaman Jul 03 '13 at 11:05
  • Your code looks reasonable to me too. How are the progress views created and hooked up in the download items? And did you try debugging `removeAllProgressbarsIfvisible`? Does `progress` have any value different from null? – Hermann Klecker Jul 03 '13 at 11:09

2 Answers2

1

try like this,in button action action method put this code

for(UIView *view in self.view.subviews){
        if([view isKindOfClass:[UIProgressView class]]))
            [view removeFromSuperView];
    }
Balu
  • 8,470
  • 2
  • 24
  • 41
  • That would work only if all progress views are direct subviews on the very next level of self.view. If the progress view is a subview of a subview then your code as such would not remove them. – Hermann Klecker Jul 03 '13 at 11:07
  • if you are not adding progressbar directly then give yourview.subviews in the place of self.view.subviews. – Balu Jul 03 '13 at 11:09
  • Or search for the progress view subviews in a recursive way. – Hermann Klecker Jul 03 '13 at 11:11
  • 1
    Thanks Sunny. Your solution worked and you saved my whole day. Thanks once again. Have a nice day. – Hammy Jul 03 '13 at 11:14
0

Remove all progress bars from a given view:

- (void) removeAllProgressBars:(UIView *)view {

    if([view isKindOfClass:[UIProgressView class]]))
       [view removeFromSuperView];
    else 
       for (UIView *subView in view.subviews) 
         [self removeAllProgressBars:view];
}

In some other method call:

[self removeAllProgressBars:self.view];

Although I consider it bad coding style not to use curly breackets on 1-statement-bodies of for and if and else etc.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71