开发者

image cache iphone

this is a part of my code. I'm using a asyncImageView .Everything work good. But now i want to save in the iphone all images in a path. I know i have to use NSFileManager but where? EDIT: now i try with my code but nothing save when i compile on my iphone

// Configure the cell.

NSDictionary *dico = [self.pseudoOnline objectAtIndex:indexPath.row];
cell.pseudo.text = [dico objectForKey:@"pseudo"];
cell.sexe.text    = [dico objectForKey:@"sexe"];
cell.age.text     = [dico objectForKey:@"age"];


UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dico objectForKey:@"photo"]]]];  


NSString *deskTopDir = @"/Users/***/Desktop/imagesOnline";



NSString *nomPhoto = [[cell.pseudo text]stringByReplacingOccurrencesOfString:@"\n" withString:@""];;

NSLog(@"pseudo%@",nomPhoto);



NSString *jpegFilePath = [NSString stringWithFormat:@"%@/%@.jpeg",deskTopDir,nomPhoto];

NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 0.5f)]; quality
[data2 writeToFile:jpegFilePath atomically:YES];

NSLog(@"image %@",jpegFilePath);

[image release];



CGRect frame;

frame.size.width=45; frame.size.height=43;

frame.origin.x=-5; frame.origin.y=0;

asyncImageView *asyncImage = [[[asyncImageView alloc] initWithFrame:frame] autorelease];

asyncImage.tag =999;


[asyncImage loadImageFromURL:[NSURL URLWithString:[dico objectForKey:@"photo"]]];
[cell.contentView addSubview:asyncImage];



return cell;

so now it works i can download all the pi开发者_JAVA技巧ctures. But now i want to load them


I'm not sure what asyncImageView is, but it appears to get an image. If it gets the image the way your code implies, you can put your NSFileManger method call right after:

 [cell.contentView addSubview:asyncImage];

If, on the other hand, the asyncImageView fetches the image asynchronously (as it's name implies), then you should put your NSFileManager method call in asyncImageView's callback delegate.

Basically, as soon as you actually have the image, you can save the image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜