views:

714

answers:

1

Hi, 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.

A: 

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)

marcc
Hi, Marcc,I tried your performSelector approach to no avail. The setProgressBar method got called AFTER all my other code completed. I didn't even try to update the UIProgressView. I simply put an NSLog in setProgressBar and that came out on the console AFTER all the other resource loading methods. Any other suggestions ? Can you point me to a reference for maybe doing all this stuff on another thread ?
kspeacock
Oops. So the idea is right, you need to update the data on one thread and not block the main thread (UI thread) while doing it. I think you actually need to use performSelectorOnMainThread if you take this approach (search in the developer site for the docs on this one).
marcc