Hi AGoodKeenMan,
Thank you for your comment. Do you think you might elaborate just a bit on exactly how to use performSelectorInBackgroun
Main Topics
Browse All TopicsHi everyone,
I have a UIProgressView that I want to update within a for loop, see the code. However, the progress view won't update itself while in the for loop, it just jumps from 0 to 1! Is this a matter of the progress view not being fast enough? What is the deal here, and how can I make this progress view work?
Thanks in advance for your help!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ok, this is a bit rough, but assuming an IBAction starts theLongTask, the following code should work as a test.
Also I meant NSNotificationCenter in the above comment, It would be a nice solution aswell. You can read more here:
http://developer.apple.com
http://developer.apple.com
Hey,
Thanks again for the code. I tried it out and I'm not getting any changes in the result. I had a couple questions:
1) How come you're never using the variable "pool"? Does that variable have any purpose?
2) How come you're setting waitUntilDone to NO, isn't the whole point to make it wait until the update is done and only then continue? However, I tried it with it set to YES and it didn't make any difference at all.
3) Did that code work for you?
I'm very frustrated. This seems to be too hard for what it is - if this is as hard as it appears to be then Apple made a huge mistake with this UIProgressView class. People should be able to update a progress bar without having to - sleep the main thread - or any other voodoo.
Here's the basic code as I have it. Any other ideas?
Sorry I didn't mean to overwhelm you. Please don't get put off, its probably my fault for not explaining things well enough.
1. Every new thread we start should have an autorelease pool and since your downloadNow method is run in a background thread it needs its own autorelease pool. You can read more about it here:
http://developer.apple.com
2. If waitUntilDone is set to YES, the background thread will wait until setProgressBar returns before it resumes execution. Which would halt the download for a short period of time and we don't want that. You can read more about NSObject here:
http://developer.apple.com
3. Yes, I just tested it in a new project.
The reason I sleep the background thread is just to simulate your download process and give you some visual feedback, it is not necessary for your solution, however if you don't have some sort of delay in this example the progress bar will appear to go from 0 to 1 instantly, because without anything for the for loop to do, it will execute very fast.
In your code above what is the value of iIterations?
I am not at work at the moment, but in the morning I will post a link so you can download myTest example.
Well, I accept that your solution works - turns out my problem must be something else. One of the things I'm doing many times while downloading is calling an outside C++ class, and the program keeps crashing on that line (accessing bad memory). But, before it does, I can see the progress view update itself. I don't know why it's crashing, it must have something to do with the different threads because the class works like a charm normally. Oh well, thanks for all your help.
Business Accounts
Answer for Membership
by: AGoodKeenManPosted on 2009-05-21 at 13:48:10ID: 24445728
I'm not 100% certain on this, but I think the UI can only be updated on the main thread, so if the main thread is busy doing aLongTask: then the UI is not updated until the aLongTask: returns, so you may need to perform the download in a background thread with performSelectorInBackgroun d:@selecto r() and then update your UIProgressView with performSelectorOnMainThrea d:@selecto r(). Also you could use the UINotificationCentre