0

我陷入了隐藏的问题。我想从 Superview 中删除所有 UIProgressView。我正在以这种方式创建十字按钮,

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];
                                     }];

当单击它时,会在层次结构中调用以下方法

-(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];
        }
    }
 }

我猜每段代码都是正确的,但不知道为什么他们不删除。

提前致谢。

4

2 回答 2

1

像这样尝试,在按钮动作动作方法中输入这段代码

for(UIView *view in self.view.subviews){
        if([view isKindOfClass:[UIProgressView class]]))
            [view removeFromSuperView];
    }
于 2013-07-03T11:02:31.770 回答
0

从给定视图中删除所有进度条:

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

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

在其他一些方法调用中:

[self removeAllProgressBars:self.view];

尽管我认为在 for 和 if 和 else 等的 1 语句体上不使用花括号是不好的编码风格。

于 2013-07-03T11:16:32.643 回答