0

Here is how I am attempting to update my UIProgressView in my iOS app.

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

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

Why is NSLog outputting 0.0? Shouldn't it output 0.3? The progress bar isn't changing either.

4

1 回答 1

0

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

如果这没有帮助,您可能需要明确地给 runloop 一些时间来赶上 UI 更改,例如使用:

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

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

于 2012-05-02T22:09:24.230 回答