【发布时间】:2014-03-25 12:09:37
【问题描述】:
我正在 UItableViewCell 中从服务器加载图像。
由于每个图像需要 10MB 大小,因此会导致内存问题。
每当我滚动到tableView 时,应用程序就会崩溃
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
locationcellObject=[self.tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
NSDictionary *temp= [sortedArray objectAtIndex:indexPath.row];
locationcellObject.title.text=[temp objectForKey:@"locationtitle"];
locationcellObject.subtitle_Lbl.text=[temp objectForKey:@"category"];
NSString *trimmedtitle = [[temp objectForKey:@"locationtitle"]stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *name=[NSString stringWithFormat:@"images/%@.png",trimmedtitle];
NSString *imageName=[NSString stringWithFormat:@"http://my_URL_HERE/%@",name];
_tempData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]];
UIImage *display=[[UIImage alloc]initWithData:_tempData];
locationcellObject.locationPic_img_View.image=display;
locationcellObject.locationPic_img_View.contentMode=UIViewContentModeScaleAspectFit;
return locationcellObject;
}
有什么简单的方法吗??
【问题讨论】:
-
你在哪里分配你的单元格?
-
为什么要为单元格使用 10MB 的图像?较小尺寸的图像就足够了,因为它可能无论如何都会被缩放(除非您的单元格大小与图像一样大)
-
我为
Cell创建了一个NSObject,并在ViewDidLoad中分配了它 -
@giorashc 是的,我的单元格将占据屏幕的一半
标签: ios objective-c uitableview uiimage