Baub
Baub

Reputation: 5044

UIProgressView not showing on iPhone but shows in simulator

I have a UIProgressView called progTimer that I placed on my View Controller via Interface Builder. On the iOS simulator, the UIProgressView shows up just fine, but when I test it on my iPhone it doesn't appear.

Here is the code that modifies it.

- (IBAction)scanbtn
{
    [progTimer invalidate];//cancels timer if currently running
    progTimer=nil;
    progNum = 0;
    progTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 //timer to update the progress view
                                               target:self 
                                             selector:@selector(progIncrease)
                                             userInfo:nil
                                              repeats:YES];
    [self scan];
}
-(void) progIncrease
{
    progNum = progNum + 0.01;
    scanProg.progress = progNum;
    if (progNum >=1)
    {
        [progTimer invalidate];
        progTimer=nil;
        //[alert show];
    }
}

Any ideas? Thanks in advance. .

Upvotes: 2

Views: 1582

Answers (3)

Baub
Baub

Reputation: 5044

ALL: For some reason, I changed the style of the Progress View to "Bar" and it shows up fine. No idea what caused the initial problem, but now it works albeit having a different style bar.

Upvotes: 2

user859375
user859375

Reputation: 3699

You call [self scan]; which seems to be the culprit. How long does that scan operation run?

Its very important to note that while any long running operation runs in main thread which is UI thread, no other code in the main thread loop will be executed(until that long running operation finishes) which means your timer function or even pressing button after pressed once pressed won't work. You need to use either NSOperation and dispatch queue or create a thread and run the scan operation in the background and send notifications to main thread using NSMachPort or NSObject performSelectr:OnThread:... etc for it to update the progress bar.

By the way, the scanning process and the progress bar has no relation at all; The progress bar should ideally update how much of scanning is done which means the scanning process must inform progress bar to update that also in main thread if scanning is running in secondary thread.

Upvotes: 1

Cyprian
Cyprian

Reputation: 9453

My guess would be that on the device, the scanning process is moving so fast that you just can't see it. To make sure it's working ad and NSLog in the ProgressIncrease method to see how fast it scans. I had the same problem with my preloading notifiers, that were showing on the simulator but not on the device.

Upvotes: 1

Related Questions