我在从数组中获取的表格视图单元格中添加了一个图像。表格中显示的图像正确显示单元格。但是,当我滚动表格视图时,它变慢并且卡住了。帮我编码。
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;
答案 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;
});
});