性能问题缓存图像UITableView

我正在解析RSS提要,然后从rss提要缓存图像,然后在单元格的imageview中显示它们。但是我使用的方法会减慢rss feed的解析时间,并减慢TableView的滚动时间。请问你能告诉我如何加快这个过程。其中一个图片链接是:http://a1.phobos.apple.com/us/r1000/009/Video/95/5d/25/mzl.gnygbsji.71x53-75.jpg,其中一个RSS提要我我试图解析的是:http://itunes.apple.com/au/rss/topmovies/limit=50/xml。这是我用来缓存图像的代码:
- (UIImage )getCachedImage: (NSString)url
{

UIImage* theImage = [imageCache objectForKey:url];

if ((nil != theImage) && [theImage isKindOfClass:[UIImage class]]) {
    return theImage;
}
else {
    theImage = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString: url]]];
    [imageCache setObject:theImage forKey:url];
    return theImage;
     } 
}
我用来获取图像的代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...
 int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
 int wierd = storyIndex *6;
 cell.textLabel.text = [[stories objectAtIndex: storyIndex] objectForKey: @"songtitle"];
 cell.detailTextLabel.text = [[stories objectAtIndex:storyIndex] objectForKey:@"artist"];

 if ([imageLinks count] != 0) {
  cell.imageView.image = [self getCachedImage:[imageLinks objectAtIndex:wierd]];
 }
    return cell;
 }
正如您可能看到的,我使用名为imageLinks的NSMutableArray来存储imageLinks。但是我从rss feed获得三个图像链接,这意味着如果我尝试获取缓存的图像:[imageLink objectAtIndex:storyIndex],图像位于错误的位置,但是如果我得到缓存的图像:[imageLink objectAtIndex:它似乎完美无缺。所以如果你能看到修复,那就太好了。 提前致谢。     
已邀请:
您的问题是您正在使用
dataWithContentsOfURL
这是一个阻止API。这意味着它将与您的UI一起在主线程上执行,并将阻止您的UI直到它完成。这是不好的。 您应该查看
NSURLConnection
类及其委托协议,
NSURLConnectionDelegate
以异步方式进行数据下载,而无需手动生成和管理新线程。     

要回复问题请先登录注册