user1940136
user1940136

Reputation: 343

Why does UIProgressView not update?

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 {

}

}

Upvotes: 1

Views: 8547

Answers (4)

Vincent
Vincent

Reputation: 4409

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.

Upvotes: 0

HugoMasterPL
HugoMasterPL

Reputation: 219

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];
}

Upvotes: 1

OlavJ
OlavJ

Reputation: 365

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?

Upvotes: 2

Zachary Christopoulos
Zachary Christopoulos

Reputation: 643

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.

Upvotes: 1

Related Questions