简体   繁体   中英

UIProgressView paused progressing when user is scrolling UITableView in iOS

In UIView I have taken one UIProgressView to show the Progress of the data downloaded from the server and to show those data I have taken an UITableView . The web service is via Polling, so which data is loading, I am loading it into an UITableView . But when user is scrolling the UITableView the ProgressBar paused its progress, but when again I am stopping my manual scroll of UITableView that time again the Progress bar is starting its progress from last paused position.

Code which I have Written:

Taken an outlet:

IBOutlet UIProgressView *pgrsVw;

When I am starting my web service call:

pgrsVw.progress = 0.0;
pgrsVw.hidden=false;
[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];

Now to show the Progress:

- (void)makeMyProgressBarMoving
{
    float actual = [pgrsVw progress];
    if (actual < 1)
    {
        pgrsVw.progress = actual + PROGRESSOFDATA;
        [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
    }
    else
    {
        pgrsVw.progress=1.0;
        pgrsVw.hidden=true;
    }
}

Now when the data downloading is completed:

pgrsVw.progress=1.0;

I have just changed my timer code, Now it is working fine. That mean when data is loading in background, the progress bar is also moving when user is scrolling the tableview.

Changed code:

NSTimer *timer = [NSTimer timerWithTimeInterval:0.10 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM