0

我需要能够将 id 作为参数与 URL 一起发送。然后程序需要异步下载图像并在 uitableview 单元格中显示图像。我怎样才能做到这一点?这是我到目前为止所拥有的:

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

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"lisn"];

        cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"lisn"] autorelease];


    [[cell textLabel] setFont:[UIFont systemFontOfSize:14.0]];
    switch([indexPath section]){
        case 0:
            cell.textLabel.text=[arryList objectAtIndex:indexPath.row];
            CGRect memberFrame=CGRectMake(240,18,10,30);
            UILabel *members=[[[UILabel alloc] initWithFrame:memberFrame ] autorelease];
            members.text=[arryList objectAtIndex:indexPath.row + 3];
            [cell.contentView addSubview:members];

            break;
        case 1:

            cell.textLabel.text=@"Start date:";
            CGRect dateFrame=CGRectMake(80,6,180,20);
            UILabel *sDate=[[[UILabel alloc] initWithFrame:dateFrame] autorelease];
            sDate.text=[arryList objectAtIndex:indexPath.row + 1 ];
            [cell.contentView addSubview:sDate];
            cell.detailTextLabel.text=@"End date:";
            CGRect enddateFrame=CGRectMake(80,22,180,50);
        UILabel *eDate=[[[UILabel alloc] initWithFrame:enddateFrame] autorelease];
            eDate.text=[arryList objectAtIndex:indexPath.row + 2];
            [cell.contentView addSubview:eDate];

            break;
        case 2:
            cell.textLabel.text=[arryList objectAtIndex:indexPath.row + 4];

            break;
        case 3:
            cell.imageView.image = [UIImage imageNamed:@"ic_place_holder_small.png"];
            break;
        break;
    }

    return cell;
}
4

1 回答 1

0

这是我用于类似问题的:(缩略图是要加载到单元格中的图片)

static NSString *CellIdentifier = @"FlickrPhotoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

OFPhotoModel *photo = [self.photos objectAtIndex:indexPath.row];

cell.textLabel.text = photo.title;
if (photo.thumbnail)
    cell.imageView.image = photo.thumbnail;
else {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        if (!photo.thumbnail) {
            photo.thumbnail = [OFManager thumbnailForPhoto:photo];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
            });
        }
    });

    cell.imageView.image = [UIImage imageNamed:@"placeholder.png"];
}

return cell;

考虑到这个实现除了两种情况外都有效: - 数组被清除并重新加载(嗯..它仍然可以通过一些修改来工作) - 无法重新排序行(在这种情况下,您必须跟踪新的 indexPath对象)

于 2012-04-20T10:26:01.940 回答