how to use the progress bar in the iphone app

為{幸葍}努か 提交于 2019-11-28 04:11:14

first you create IBOutlet in .h file

IBOutlet UIProgressView * threadProgressView;

Then in .m file in viewdidload first set progress to 0.0 and then call makeMyProgressMoving method

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

then add below method

- (void)makeMyProgressBarMoving {

        float actual = [threadProgressView progress];
        if (actual < 1) {
            threadProgressView.progress = actual + ((float)recievedData/(float)xpectedTotalSize);
            [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
        }
        else{



        }

    } 

also give your review for answer. is it useful to you?

It is quite simple. You just need to set appropriate value of property progress of UIProgressView.

In delegate of NSURLConnection you should receive the amount of data you are waiting to download and update the progress during downloading. Progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the completion of the task.

Ketan Shinde

You can display progress of progress bar with these line of code

-(void) connection:(NSURLConnection *) connection 
didReceiveData:(NSData *) data {
   if (file)
   { 
       [file seekToEndOfFile];
        progressView.progress = ((float)recievedData / (float) xpectedTotalSize);
   } 
     [file writeData:data];
     recievedData += data.length;
     NSLog(@"Receiving Bytes: %d", recievedData);
}

One of the option is AFNetworking. AFURLConnectionOperation also allows you to easily stream uploads and downloads, handle authentication challenges, monitor upload and download progress, and control the caching behavior or requests.

noted: self.progressionBalance.progress = 5.0/10.0;

you must set decimal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!