0

我正在实现一个延迟加载的示例代码。我有一个数组,其中包含 10url 的图像:-//自定义表格视图单元格的外观。

- (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];
    }

    iconDownloader = [imageDownloadsInProgress objectForKey:indexPath];

    if (!iconDownloader.ImageDispaly)
    {
        if (Tble.dragging == NO && Tble.decelerating == NO)
        {
            [self startIconDownload:[ArrayImage objectAtIndex:indexPath.row] forIndexPath:indexPath];
        }

        //cell.imgView.image = [UIImage imageNamed:@"event_image.png"];
        cell.imageView.image=[UIImage imageNamed:@"default-image.png"];
        NSLog(@"image not download");
    }
    else
    {
        //cell.imgView.image=[aTweet objectForKey:@"image"];
        cell.imageView.image=iconDownloader.ImageDispaly.image;

    } 

    return cell;
}


#pragma mark -
#pragma mark Table cell image support
- (void)startIconDownload:(NSString *)str forIndexPath:(NSIndexPath *)indexPath
{
    //[imageDownloadsInProgress retain];
    iconDownloader = [imageDownloadsInProgress objectForKey:indexPath];
    if (iconDownloader == nil) 
    {
        iconDownloader = [[IconDownloader alloc] init];
       // iconDownloader.appRecord = aTweet;
        iconDownloader.imageurlstring=[ArrayImage objectAtIndex:indexPath.row];
        iconDownloader.indexPathInTableView = indexPath;
        iconDownloader.delegate = self;
        [imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
        [iconDownloader startDownload];
        [imageDownloadsInProgress retain];
        [iconDownloader release];   
    }
}

// this method is used in case the user scrolled into a set of cells that don't have their app icons yet
- (void)loadImagesForOnscreenRows
{
    if ([ArrayImage count] > 0)
    {
        NSArray *visiblePaths = [Tble indexPathsForVisibleRows];
        for (NSIndexPath *indexPath in visiblePaths)
        {
            iconDownloader =[imageDownloadsInProgress objectForKey:indexPath];

            if (!iconDownloader.ImageDispaly) // avoid the app icon download if the app already has an icon
            {
                [self startIconDownload:[ArrayImage objectAtIndex:indexPath.row] forIndexPath:indexPath];
            }
        }
    }
}

- (void)appImageDidLoad:(NSIndexPath *)indexPath
{
    iconDownloader =[imageDownloadsInProgress objectForKey:indexPath];
    if (iconDownloader != nil)
    {

        UIImageView *image=[[UIImageView alloc] initWithFrame:CGRectMake(10,5,60,60)];
        UITableViewCell *cell = [Tble cellForRowAtIndexPath:iconDownloader.indexPathInTableView];
        // [cell.btnImage setBackgroundImage:[iconDownloader.appRecord valueForKey:@"image"] forState:UIControlStateNormal];
        image.image=iconDownloader.ImageDispaly.image;
        cell.imageView.image=image.image;

        NSLog(@"%@ ======%@",cell.imageView.image,image.image);

    }

}

这就是我在控制台上得到的 NSLog(@"%@ ======%@",cell.imageView.image,image.image); 在执行应用程序时

2012-05-28 16:41:44.998 Lazyloading[97195:207] <UIImage: 0x4b56300> ======<UIImage: 0x4b56300>
2012-05-28 16:41:44.999 Lazyloading[97195:207] <UIImage: 0x4e24f00> ======<UIImage: 0x4e24f00>
2012-05-28 16:41:45.000 Lazyloading[97195:207] <UIImage: 0x4b55df0> ======<UIImage: 0x4b55df0>
2012-05-28 16:41:45.001 Lazyloading[97195:207] <UIImage: 0x4b406e0> ======<UIImage: 0x4b406e0>
2012-05-28 16:41:45.260 Lazyloading[97195:207] <UIImage: 0x4e2f9f0> ======<UIImage: 0x4e2f9f0>
2012-05-28 16:41:45.263 Lazyloading[97195:207] <UIImage: 0x4e0a2e0> ======<UIImage: 0x4e0a2e0>
2012-05-28 16:41:45.294 Lazyloading[97195:207] <UIImage: 0x4b40180> ======<UIImage: 0x4b40180>

但是图像没有显示在tableview中..任何人都可以帮我解决这个问题..

4

1 回答 1

0

尝试调用:

[cell setNeedsDisplay];

您的 NSLog 行在哪里:

NSLog(@"%@ ======%@",cell.imageView.image,image.image);
于 2012-05-28T11:09:49.667 回答