我的问题是这样的:
我想显示 ProgressView 用于文件下载。由于某种原因,ProgressView 逐渐上升,显示已经下载了多少文件,当文件仍未下载时立即填满!我需要修复什么或如何实施它?
这是我的源代码:
- (IBAction)download:(id)sender {
// Determile cache file path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
progressSlider.progress = 0.0;
for (i=0;i<=7;i++) {
//Updating progressView and progressLabel
progressLabel.text = [NSString stringWithFormat:@"Загружено: %d из 7",i];
progressView.progress = (float)i/(float)7;
NSString *filePath = [NSString stringWithFormat:@"%@/avto-0-%d.html", [paths objectAtIndex:0],i];
// Download and write to file
NSString *mustUrl = [NSString stringWithFormat:@"http://www.mosgortrans.org/pass3/shedule.php?type=avto&%@", [listOfAvtoUrl objectAtIndex:i]];
NSURL *url = [NSURL URLWithString:mustUrl];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
}
}