UITableViewCell在其中显示UIImage。
图像从服务器获取,并作为NSData存储在NSDictionary中。
使用下面列出的UIImageGraphicsBeginImageContext为非视网膜设备调整此图像的大小。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
NSDictionary *myDictionary=[self.tableObject objectAtIndex:indexPath.row];
NSData *imgData=[myDictionary objectForKey:@"icon"];
UIImage *img=[UIImage imageWithData:imgData];
if(isRetina]){
cell.iconImageView.image=img;
}else{
CGRect imgRect=CGRectMake(0, 0, img.size.width/2.0, img.size.height/2.0);
UIGraphicsBeginImageContext(imgRect.size);
[img drawInRect:imgRect];
UIImage *newImg=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.iconImageView.image=newImg;
}
}
是更好的方法和更少的内存密集,还是应该将其存储在磁盘中,然后从中访问图像并将其分配给cell.iconImageView.image;
答案 0 :(得分:0)
下载时将其写入磁盘。
那样,操作系统可以懒得读取数据,缓存它而你的内存中没有图像数据