嗨,我的問題是,當我滾動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