Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在TableViewCell中显示图像(从JSON服务动态检索)_Iphone_Objective C_Xcode_Image_Tableviewcell - Fatal编程技术网

Iphone 如何在TableViewCell中显示图像(从JSON服务动态检索)

Iphone 如何在TableViewCell中显示图像(从JSON服务动态检索),iphone,objective-c,xcode,image,tableviewcell,Iphone,Objective C,Xcode,Image,Tableviewcell,我从JSON服务获取url图像。我知道如何使用UIImageView对象在屏幕上显示它,但我不知道如何在UITableViewCell中显示它,因为我无法将UIImageView对象拖放到原型单元格上。我查看了一些资源,但它们都非常混乱,在屏幕上显示图像和在UITableViewCell上显示图像之间的区别也不清楚。我相信这篇文章的回复将有助于解决像我这样的开发者的困惑 我的问题是,在屏幕上显示图像与在代码级别的UITableViewCell上显示图像有什么区别?(我们是否也在UITableVi

我从JSON服务获取url图像。我知道如何使用
UIImageView
对象在屏幕上显示它,但我不知道如何在
UITableViewCell
中显示它,因为我无法将
UIImageView
对象拖放到原型单元格上。我查看了一些资源,但它们都非常混乱,在屏幕上显示图像和在
UITableViewCell
上显示图像之间的区别也不清楚。我相信这篇文章的回复将有助于解决像我这样的开发者的困惑


我的问题是,在屏幕上显示图像与在代码级别的
UITableViewCell
上显示图像有什么区别?(我们是否也在
UITableViewCell
中使用
UIImageView
对象?我们是否拖放任何东西?我们是否需要
contentView
子视图
?等)

看看这个非常好的教程。它不应该让你的任何问题悬而未决


我不建议采用这种方法。表视图有很多行,因此图像太小。只有当图像像横幅时才这样做

解决方案

如果仍要上载不同行中的每个图像(因此在单元格中),可以返回包含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;
}
替代解决方案


如果您希望显示大图像,只需监视行选择,将大图像放在表视图下方,并在行选择更改时更改图像井内容

如果您使用的是默认UITableViewCell,则它有一个名为imageView的属性。您可以将图像设置为此imageView