2

我正在使用 setImageWithURL 将图像延迟加载到我的 tableview 单元格中,但是有一个问题。它可以很好地加载图像,但设备上似乎存在刷新问题,其中图像仅在您将它们滚动出视图并再次滚动时才会显示。

它在模拟器中完美运行。该设备在 iPhone 4S 上运行 iOS 5.1.1

该表显示在 UINavigation 控制器中,并且由于图像被缓存,我希望当我重新访问屏幕时图像会很快出现。他们这样做了,但显示的大小只有原来的一半。

图像尺寸为 60x30。

将图像加载到只有一半大小的视网膜屏幕上是否存在问题?什么会导致此刷新问题?

下面的代码片段...

- (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    ...
    [cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"transparent_shade"]];

    ...

    return cell;
}

提前感谢您的任何见解

4

1 回答 1

2

I would suggest loading/preparing the images before the cellForRowAtIndexPath method. The reason you are seeing the images after scrolling is because the images were previously downloading at the time this method was called, hence the files were not yet available.

Make a NSMutableArray inside your view's viewWillAppear method (override it if non-existent) for instance, and put all the images inside the array. Then, in the cellForRowAtIndexPath simply get the images from the array and assign them as needed; they should be displayed on demand, without delays.

Let us know how this works for you.

于 2012-07-12T00:01:13.910 回答