0

遅延読み込みのサンプル コードを 1 つ実装しています。私は10urlの画像を持つ1つの配列を持っています:- //テーブルビューセルの外観をカスタマイズします。

- (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>

しかし、画像はテーブルビューに表示されていません..誰かが私を助けてくれませんか..

4

1 に答える 1

0

電話してみてください:

[cell setNeedsDisplay];

NSLog 行の場所:

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