我正在解析 JSON 文件中的一些图像和字符串,解析工作正常,但图像加载非常慢。我注意到,当我按下 UITableViewCell 时,UITableView 会更快地显示内容。有谁知道解决这个问题?
这是我使用的代码,我使用 NSOperationQueue 来保持低 CPU 使用率。
NSDictionary *dict;
dict = [application objectAtIndex:indexPath.row];
name = [dict objectForKey:@"name"];
detileName = [dict objectForKey:@"detailName"];
itmsLink = [dict objectForKey:@"itms-serviceLink"];
icon = [dict objectForKey:@"icon"];
developer = [dict objectForKey:@"developer"];
version = [dict objectForKey:@"version"];
category = [dict objectForKey:@"category"];
rating = [dict objectForKey:@"rating"];
ratingNumbers = [dict objectForKey:@"ratingNumber"];
description = [dict objectForKey:@"description"];
developerEmails = [dict objectForKey:@"developerEmail"];
[downloadQueue addOperationWithBlock:^{
cell.AppName.text = name;
cell.category.text = category;
cell.rater.text = [NSString stringWithFormat:@"(%@)", ratingNumbers];
if ([rating intValue] == 1) {
cell.rating.image = [UIImage imageNamed:@"1.png"];
}
if ([rating intValue] == 2) {
cell.rating.image = [UIImage imageNamed:@"2.png"];
}
if ([rating intValue] == 3) {
cell.rating.image = [UIImage imageNamed:@"3.png"];
}
if ([rating intValue] == 4) {
cell.rating.image = [UIImage imageNamed:@"4.png"];
}
cell.itms = itmsLink;
cell.AppIcon.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:icon]]];
cell.number.text = [NSString stringWithFormat:@"%li", (long)indexPath.row + 1];
}];