Progressview没有显示

时间:2014-04-17 08:55:09

标签: objective-c progress-bar

奇怪的事情发生在这里。我在一个有tableviewcontroller的项目上工作。 headersview来自一个自定义类,它添加了progressview和一个按钮。单击该按钮时,进度视图显示下载状态,完成后将自行从屏幕中删除。这是问题所在。

进度视图未显示,也未显示其进度(蓝色)。当我将backgroundcolor设置为黑色时,我看到一个没有进展的黑条。即使我将进度设置为静态0.5f。 我也在使用revealapp,它显示了进度视图框架,但没有显示跟踪栏。

因此,进度视图在实际存在但不可见。有人知道为什么吗?

结构:

Header.m

INIT:

[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]

layoutSubviews:

CGRectMake(x, x, x, x);

然后:

- (void)synchMedia
{
     // add progressview to view
     [self performSelectorInBackground:@selector(synchMediaThread) withObject:nil];
}


- (void)synchMediaThread
{
     // Do all the heavy lifting
     // set progressview progress

     // loop this:
     [self performSelectorOnMainThread:@selector(updateProgressView:) withObject:progress waitUntilDone:YES];
     // finally
     [self performSelectorOnMainThread:@selector(synchDone:) withObject:@(numFailed) waitUntilDone:YES];
}

完成后:

- (void)synchDone {
     // remove progressview
     [tableview reloadData];
}

2 个答案:

答案 0 :(得分:1)

您下载了大量数据吗?如果是这样,那么在这种情况下,当主线程忙碌时,UI上的更新会被阻止。

要检查这一点,只需在计算下载进度的函数中添加NSLog语句。在这种情况下,它将在控制台上记录进度,但不在UI上记录。如果您在控制台上获得了正确的进度,那么当您开始下载时,确保UI更新被阻止。

尝试使用一些延迟来更新UI或

dispatch_async(dispatch_get_main_queue(), ^{
//do you code for UI updation
});

答案 1 :(得分:0)

问题在于在tableview委托中使用UIView的方式。

相关问题