1

I'm trying to set the progress of a UIProgressView, but the progressView doesn't "update". Why? Do you know what I am doing wrong?

Here is my code in ViewController.h:

    IBOutlet UIProgressView *progressBar;

That's the code in ViewController.m:

- (void)viewDidLoad
{
[super viewDidLoad];

progressBar.progress = 0.0;

[self performSelectorOnMainThread:@selector(progressUpdate) withObject:nil waitUntilDone:NO];


}

-(void)progressUpdate {

float actual = [progressBar progress];
if (actual < 1) {
    progressBar.progress = actual + 0.1;
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self `selector:@selector(progressUpdate) userInfo:nil repeats:NO];`
}
else {

}

}
user1940136
  • 343
  • 6
  • 12
  • I think you forgot to set `repeat` to `YES`. [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(progressUpdate) userInfo:nil repeats:YES]; – Paresh Navadiya Jan 04 '13 at 10:22
  • @Prince: no he don't, because he is repeatedly calling the same method. It'll again creating a timer, so no need to set the timer repeat to yes. – Midhun MP Jan 04 '13 at 10:36

4 Answers4

2

Try calling [progressBar setProgress:<value> animated:YES]; instead of progressBar.progress = <value>

EDIT: Take a look at this, which looks a lot like your example: Objective c : How to set time and progress of uiprogressview dynamically?

Community
  • 1
  • 1
OlavJ
  • 365
  • 4
  • 9
1

Double check that progressBar is linked correctly in Interface Builder.

If it still doesn't work, try using [progressBar setProgress:0]; and [progressBar setProgress:actual+0.1];.

Also know that the UIProgressView has a [progressBar setProgress:<value> animated:YES]; method. May look cleaner.

1

Its should look like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    progressBar.progress = 0.0;
    [self performSelectorInBackground:@selector(progressUpdate) withObject:nil];
}

-(void)progressUpdate {
    for(int i = 0; i<100; i++){
        [self performSelectorOnMainThread:@selector(setProgress:) withObject:[NSNumber numberWithFloat:(1/(float)i)] waitUntilDone:YES];   
    }
}

- (void)setProgress:(NSNumber *)number
{
   [progressBar setProgress:number.floatValue animated:YES];
}
HugoMasterPL
  • 209
  • 3
  • 10
0

I had the same problem this morning. It appeared that the progressBar was partly over a UITableView. I moved it a little, so that it was not overlapping anymore.

I'm not sure why this is. It should have been working in the original case, but that is how I solved it.

Vincent
  • 4,342
  • 1
  • 38
  • 37