我使用代碼顯示將文件從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