Alessandro
Alessandro

Reputation: 4110

UIProgressView won't change value

I am setting the progress to a UIProgressView :

[recordingProgress setProgress:seconds/600 animated:YES];

The line is in a timer which keeps repeating, and seconds is an integer (int) that varies from 0 to 600. I notice that if I just insert the value of 0.5, the progress bar moves. I tried using float by:

float val = seconds/600

but it still doesn't work...

Upvotes: 1

Views: 159

Answers (2)

Refael.S
Refael.S

Reputation: 1644

Try:

float value = (float)seconds / 600;

Upvotes: 0

dandan78
dandan78

Reputation: 13924

Given that seconds is also an int, then you won't be getting a floating point value as a result of your division. Cast to a float first:

float val = (float)seconds / 600.0f;

The reason for this is that dividing two ints produces an int, in this case 0 for values less than 600. The 600.0f is there to ensure that the second operand is also treated properly.

Upvotes: 2

Related Questions