2012-12-20 36 views
2

我从JSON服务中获取URL图像。我知道如何使用UIImageView对象在屏幕上显示它,但我不知道如何在UITableViewCell中执行此操作,因为我无法将UIImageView对象拖放到原型单元格上。我检查了一些资源,但它们都很混乱,在屏幕上和UITableViewCell上显示图像的区别还不清楚。我相信这篇文章的回复将有助于解决像我这样的很多开发人员的这种困惑!如何在TableViewCell中显示图像(从JSON服务动态检索)

我的问题是,在屏幕上显示图像和UITableViewCell代码级别有什么区别? (我们使用UIImageView对象UITableViewCell呢?难道我们拖放什么?我们需要contentViewsubview?等)

+0

如果您使用默认的UITableViewCell,它有一个名为imageView的属性。你可以设置图像到这个imageView –

回答

0

我不建议遵循这一approach.A表视图有很多行,因此图像会太tiny.Do仅如果图像是一样的横幅。

解决方案

如果你仍然想每个图像上传在不同的行(这样的电池),你可以返回一个细胞内部具有UIImageWiew:

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString* path; 
    ... // assign the path according to the index path, so that it loads 
    ... // a different image for every row and section 
    UIImage* image=[[UIImage alloc]initWithContentsOfFile: path]; 
    UITableViewCell* cell=[UITableViewCell new]; 
    [cell.imageView setImage: image]; 
    return cell; 
} 

替代解决方案

如果您想要显示大图像,只需监视行选择,将大图像放在表视图下方并更改im行选择改变时的年龄内容。

相关问题