开发者

Improve speed - UIImage from NSURL

开发者 https://www.devze.com 2023-01-22 20:46 出处:网络
I\'m using the following code to fetch some images, that are going into a tableview. Butit takes ages (5-6 seconds) to get the 30 images in.

I'm using the following code to fetch some images, that are going into a tableview. But it takes ages (5-6 seconds) to get the 30 images in.

Is there a smarter/faster way to do this?

NSString *imageUrl = ......;
NSString *urlStr = 
[imageUrl UrlstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[NSString alloc] initWithFormat:@"http://xxx.dk/xml.aspx%@", urlStr]; 
NSURL *url = [NSURL URLWithString:path];


NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img 开发者_StackOverflow社区= [[UIImage alloc] initWithData:data];
return img;
[..... release];


Here profileimg is an get from Api ,String name

NSString *profileimg=[Check objectForKey:@"IMAGE"];

imageview.image=[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:profileimg]]];


I'd rather download every new image in array of images when a cell appears on the screen and just display already saved image if a cell appears on the screen for the second time (i.e. image for this cell has been already downloaded).


use asynchronize loading of image. check out this sample code : http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

0

精彩评论

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

关注公众号