嗨,我的问题是,当我滚动UITableView
细胞图像实际上这些图像是在web服务器和我并使用asyncdownloading下载它。我在UITableViewCell
上添加了UIImageView
。图像成功地显示在UITableViewCell
但是当我滚动的tableview图像的变化是这样的代码单元格图像更改滚动UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell"];
searchobjectval =[self.arrSearchResult objectAtIndex:indexPath.row];
if(cell == nil)
{
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DefaultCell"];
}
UILabel *areaLbl = (UILabel *)[cell viewWithTag:1];
UILabel *postTitle = (UILabel *)[cell viewWithTag:2];
UILabel *roomCost = (UILabel *)[cell viewWithTag:3];
UILabel *description = (UILabel *)[cell viewWithTag:4];
areaLbl.text =searchobjectval.location;
postTitle.text = searchobjectval.title;
roomCost.text = searchobjectval.roomCost;
description.text =searchobjectval.description;
[tableView setSeparatorColor:[UIColor blueColor]];
UIView *myView = [[UIView alloc] init];
if (indexPath.row % 2)
{
UIColor* clr = [UIColor colorWithRed:0.4f green:0.6f blue:0.8f alpha:1];
myView.backgroundColor = clr;
}
else
{
myView.backgroundColor = [UIColor whiteColor];
}
cell.backgroundView = myView;
NSLog(@" search object image %@",searchobjectval.imgLink);
// Pass along the URL to the image (or change it if you are loading there locally)
[AsyncImagesDownloading processImageDataWithURLString:[NSString stringWithFormat: @"http://192.95.48.72/bedspace/new_arrivals_img/%@",searchobjectval.idVal ] andBlock:^(NSData *imageData)
{
if (self.view.window)
{
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imgVw = (UIImageView *)[cell viewWithTag:10];
imgVw.image = image;
}
}];
return cell;
}
对从内存清除图像扩大,'NSCache'会是一个更好的存储类;那么你不需要编写任何逻辑。或者更好,不要重新发明轮子,并使用SDWebImage。 – 2013-05-13 14:09:28