Prgmmr Prgmmr - 3 months ago 11
iOS Question

UIProgressView gets to value 100 before the actual float being 100

When using progressView inside a UITableViewCell, i use as so

cell.imageView.file = (PFFile *)object[@"image"];
[cell.imageView loadInBackground:^(UIImage * _Nullable image, NSError * _Nullable error) {

} progressBlock:^(int percentDone) {
NSLog(@"%d",percentDone);
dispatch_async(dispatch_get_main_queue(), ^{
[cell.progressBar setProgress:percentDone animated:YES];
});
if (percentDone == 100) {
[cell.progressBar setHidden:YES];
}

}];


Im NSLogging the percentDone, and the progressView gets to 100 before the percentDone gets to 100. This is on the second cell so maybe something to do with reuse?

Answer

The progress in UIProgressView is represented as a value between 0.00 and 1.00. If your values are integers 0 through 100, you want to multiply them by 0.01.

[cell.progressBar setProgress:percentDone * 0.01 animated:YES];
Comments