UIProgressView not updating?

I started playing with UIProgressView in iOS5, but havent really been lucky with it. I am having problems updating the view. I have a set of sequential actions after every update i. The problem is that the idea of ​​progress is not being updated little by little, but only after it's over. This happens something like this:

float cnt = 0.2; for (Photo *photo in [Photo photos]) { [photos addObject:[photo createJSON]]; [progressBar setProgress:cnt animated:YES]; cnt += 0.2; } 

Look, I found messages like these - setProgress no longer updates UIProgressView with iOS 5 , implying that I need to work for this, I need to start a separate thread.

I would like to clarify this, do I really need a separate thread for the UIProgressView to work?

+5
multithreading ios ios5 uiprogressview
source share
3 answers

Yes, the whole purpose of presenting progress is for streaming.

If you use this loop in the main thread, you are blocking the user interface. If you block the user interface, users can interact and the user interface cannot be updated. You have to do all the heavy lifting on the background thread and update the user interface on the main topic.

Here is a small example

 - (void)viewDidLoad { [super viewDidLoad]; [self performSelectorInBackground:@selector(backgroundProcess) withObject:nil]; } - (void)backgroundProcess { for (int i = 0; i < 500; i++) { // Do Work... // Update UI [self performSelectorOnMainThread:@selector(setLoaderProgress:) withObject:[NSNumber numberWithFloat:i/500.0] waitUntilDone:NO]; } } - (void)setLoaderProgress:(NSNumber *)number { [progressView setProgress:number.floatValue animated:YES]; } 
+18
source share

Define UIProgressView in the .h file:

 IBOutlet UIProgressView *progress1; 

In the .m file:

 test=1.0; progress1.progress = 0.0; [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO]; - (void)makeMyProgressBarMoving { NSLog(@"test %f",test); float actual = [progress1 progress]; NSLog(@"actual %f",actual); if (progress1.progress >1.0){ progress1.progress = 0.0; test=0.0; } NSLog(@"progress1.progress %f",progress1.progress); lbl4.text=[NSString stringWithFormat:@" %i %%",(int)((progress1.progress) * 100) ] ; progress1.progress = test/100.00;//actual + ((float)recievedData/(float)xpectedTotalSize); [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO]; test++; } 
+2
source share

I had a similar problem. UIProgressView did not update, although I did setProgress and even tried setNeedsDisplay, etc.

 float progress = (float)currentPlaybackTime / (float)totalPlaybackTime; [self.progressView setProgress:progress animated:YES]; 

I had (int) before progress in partProgress. If you call setProgress with int, it will not be updated as UISlider. You need to call it with a float value only from 0 to 1.

+1
source share

All Articles