图像添加时表格视图变慢

时间:2015-02-13 10:03:11

标签: ios objective-c uitableview uiimage

我在从数组中获取的表格视图单元格中添加了一个图像。表格中显示的图像正确显示单元格。但是,当我滚动表格视图时,它变慢并且卡住了。帮我编码。

NSString *imageUrlString = [NSString stringWithFormat:@"http://www.progolmexico.com/static/logo/%@",[[array objectAtIndex:indexPath.row ] valueForKey:@"team_logo"]];
 NSURL * imageURL = [NSURL URLWithString:imageUrlString];
    NSData *data = [NSData dataWithContentsOfURL:imageURL];
  UIImage *cachedImage = [[UIImage alloc] initWithData:data];
    cell.pteam.image = cachedImage;

1 个答案:

答案 0 :(得分:0)

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
NSString *imageUrlString = [NSString stringWithFormat:@"http://www.progolmexico.com/static/logo/%@",[[array   objectAtIndex:indexPath.row ] valueForKey:@"team_logo"]];
     NSURL * imageURL = [NSURL URLWithString:imageUrlString];
     NSData *data = [NSData dataWithContentsOfURL:imageURL];
     UIImage *cachedImage = [[UIImage alloc] initWithData:data];
    dispatch_async(dispatch_get_main_queue(), ^(void){
     cell.pteam.image = cachedImage;
    });
});