kspeacock
kspeacock

Reputation: 173

UIProgressView not updating while my App loads its resources

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.

Upvotes: 2

Views: 2433

Answers (2)

Ivan Vučica
Ivan Vučica

Reputation: 9679

You could run a step of the runloop after each update of the UI:

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

It could have other bad consequences (for example, enable user to interact with the UI, execute delegates of view controller such as viewDidAppear before they should be executed, etc) so be very, very careful.

Upvotes: 0

marcc
marcc

Reputation: 12399

Yes. Load them on a separate thread. Or just use something like performSelector:

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

(and create a setProgressBar function which reads the current value from a member variable and updates the UI)

Upvotes: 1

Related Questions