为什么我的UI进度条没有更新?

时间:2012-05-02 20:50:31

标签: objective-c ios

以下是我尝试在iOS应用中更新UIProgressView的方法。

[self.progressView setProgress:3.0/10.0 animated:YES];

// check the value.
NSLog(@"Progress: %0.1f", self.progressView.progress);

为什么NSLog输出0.0?不应该输出0.3吗?进度条也没有改变。

1 个答案:

答案 0 :(得分:0)

首先,确保在主线程上设置进度值。 (并且self.progressView实际上是指您的UIProgressView

如果这没有帮助,您可能希望明确地给runloop一些时间来了解UI更改,例如:使用:

NSDate* futureDate = [NSDate dateWithTimeInterval:0.001 sinceDate:[NSDate date]];
[[NSRunLoop currentRunLoop] runUntilDate:futureDate];

但是,你应该非常小心使用这样的黑客,请参阅: