imagesArray = [[NSArray alloc]initWithObjects:@"http://farm3.static.flickr.com/2887/9391679341_266553bcafa_b.png",@"http://farm3.static.flickr.com/2897/9391679341_26643bcafa_b.png",@"http://farm3.static.flickr.com/2887/9691679341_26643bcafa_b.png",@"http://farm3.static.flickr.com/2887/9391679341_26644bcafa_b.png",@"http://farm3.static.flickr.com/2887/9391679341_26643bcafa_b.png",@"http://farm3.static.flickr.com/2887/9391679341_26643bcafa_b.png",@"http://farm3.static.flickr.com/2887/9391679341_26643bcafa_b.png",@"http://farm3.static.flickr.com/2887/9391679344_26643bcafa_b.png", nil ];
数组有很多URL,加载进度视图
完整数组加载进度视图
答案 0 :(得分:2)
如果您想暂时保存,请使用NSUserDefaults并设置您的可变数组对象。因此它将本地保存到您的磁盘
答案 1 :(得分:1)
UIProgressView *progressVieww =
[[UIProgressView alloc] init];
// configure the progress view and add it to
your UI
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (int i=0; i<[array count]; i++)
{
NSError *error;
NSArray *ipaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *idocumentsDir = [ipaths objectAtIndex:0];
NSString *idataPath = [idocumentsDir stringByAppendingPathComponent:@"File"];
NSLog(@"idataPath:%@",idataPath);
//Create folder here
if (![[NSFileManager defaultManager] fileExistsAtPath:idataPath])
{
[[NSFileManager defaultManager] createDirectoryAtPath:idataPath withIntermediateDirectories:NO attributes:nil error:&error];
}
// Image Download here
NSString *fileName = [idataPath stringByAppendingFormat:@".jpg"];
NSLog(@"imagePathDOWNLOAD:%@",fileName);
_imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[array objectAtIndex:i]]];
[_imgData writeToFile:fileName atomically:YES];
// now dispatch any UI updates back to the main queue
dispatch_async(dispatch_get_main_queue(), ^{
[progressView setProgress: (CGFloat) (i + 1.0) / [array count] animated:YES];
tempImg.image = [UIImage imageWithData:_imgData];
});
}
});