1
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,加载进度视图

完整的数组加载到进度视图上

4

2 回答 2

2

如果您想暂时保存,请使用 NSUserDefaults 并将您的对象设置为可变数组。所以它将本地保存到您的磁盘

于 2013-11-07T11:05:46.310 回答
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];
        });
    }
});
于 2013-11-08T06:38:51.583 回答