vshall
vshall

Reputation: 619

How to know about the progress of uiprogressview?

I am making an application in which i have put a progress bar .

I just need to know about the progress of the bar...

How will i come to know about the progress..

Even i want the print the progress bar in a label time to time..

Here, is my code

[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
-(void) onTimer {

    [progressView setProgress:5 animated:YES];


    sliderLabel.text=[NSString stringWithFormat:@"%0.2f",progressView.progress *100];

}

Here ,i have set a timer in viewdidLoad and as and when the progress is raised ,the label

should get updated .

Kindly help.

Thanks,

Upvotes: 0

Views: 1156

Answers (1)

Kapil Choubisa
Kapil Choubisa

Reputation: 5232

First thing you are doing wrong. Every time your timer invoke you are setting your progressView's progress to 5. So it won't actually progress.

Now for getting your progressView's actual progress you can use progress property of UIProgressView.

[The current progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the completion of the task. The default value is 0.0. Values less than 0.0 and greater than 1.0 are pinned to those limits.]

see UIProgressView

UIProgressView have progress between 0.0 to 1.0. 1.0 represent 100% so if you want to set progress somewhere set it between 0.0-1.0.

Edit:

Do one thing you know about timer. Create two timer one for setting progressView's progress. don't make it fix. Take a global float value first time 0.0. Every time your timer invoke add some thing in that value let say you are adding 0.1 every time. So when your timere invoke 10th time your value will be 1.0. and your progressView will have progress increasing.

- (void)onTimer {
    myValue += 0.1;
    [progressView setProgress:myValue];
}

myValue will be a float declared in .h file.

In your second timer you can print the progress of your progressview as you are doing right now. but don't set progress again in second view.

Hope this helps

Upvotes: 1

Related Questions