我使用代码显示将文件从1%下载到100%的进度。在标签中显示百分比
if(downloadTask == _downloadTask26){
_progress26 = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
_total26 = [[NSNumber numberWithInteger:totalBytesExpectedToWrite] floatValue];
}
if(downloadTask == _downloadTask27){
_progress27 = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
_total27 = [[NSNumber numberWithInteger:totalBytesExpectedToWrite] floatValue];
}
float progress = _progress26 + _progress27;
float total = _total26 + _total27;
NSString *percentage = [NSString stringWithFormat:@"%.f%%", ((progress/total) * 100)];
(NSLog (percentage, @"%.f%%"));
if (!_label3) {
_label3 = [[UILabel alloc] initWithFrame:CGRectMake(200.43, 158.84, 42, 19)];
_label3.numberOfLines = 1;
_label3.baselineAdjustment = UIBaselineAdjustmentAlignBaselines;
_label3.adjustsFontSizeToFitWidth = YES;
_label3.minimumScaleFactor = 10.0f/12.0f;
_label3.clipsToBounds = YES;
_label3.backgroundColor = [UIColor clearColor];
_label3.textColor = [UIColor whiteColor];
_label3.textAlignment = NSTextAlignmentCenter;
[_scroller addSubview:_label3];
}
}
_label3.text = percentage;
if ([_label3.text isEqual: @"100%"]) {
}
但是,当文件下载时,百分比不是以升序显示。百分比以不同的顺序显示,如下面的视频所示。我如何解决它?
视频 https://drive.google.com/file/d/0B0EJbcHq3ZALUVRzanJ6SndscWc/view
是的,我简化了代码,因为它非常大。你能展示如何在我的代码中正确添加NSProgress吗? – wefagaefesfsefsef
查看优秀的WWDC 2015视频[最佳进度报告实践](https://developer.apple.com/videos/play/wwdc2015/232/)。 – Rob