2

I am trying to update a UIProgressView progress bar that I have in a UIView during a long resource loading process. Let's say I'm loading a bunch of bitmaps from a NIB file (like maybe a hundred). After I load 10, I issue a .progress to the UIProgressView that is part of a UIView that is already being displayed. So, I issue:

myView.myProgressView.progress=0.2;

Then, I load another 10 bitmaps, and issue:

myView.myProgressView.progress=0.4;

etc., etc. When the app runs, the progress bar doesn't advance. It simply stays at its initial position. At the risk of sounding like a complete moron, do I have to load my resources on a separate thread so the OS can update the UI, or, is there an easier way? Thanks for any assistance.

4

2 回答 2

1

是的。将它们加载到单独的线程上。或者只是使用类似的东西performSelector

[self performSelector:@selector(setProgressBar) withObject:nil afterDelay:0.0];

(并创建一个setProgressBar从成员变量中读取当前值并更新 UI 的函数)

于 2009-08-07T02:44:24.853 回答
0

您可以在每次更新 UI 后运行 runloop 的一个步骤:

SInt32 result;
do {
    result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
} while(result == kCFRunLoopRunHandledSource);

它可能会产生其他不良后果(例如,使用户能够与 UI 交互,执行视图控制器的委托,例如viewDidAppear在它们应该被执行之前等等)所以要非常非常小心。

于 2011-05-14T18:00:17.247 回答