Question

I get the url image from a JSON service. I know how to display it on a screen using an UIImageView object but I don't know how I can do it in a UITableViewCell cause I cannot drag and drop the UIImageView object onto a prototype cell. I checked some of the resources but they are all very confusing and the difference between displaying an image on the screen and on the UITableViewCell is not clear. I am sure replies of this post will help solving this confusion for a lot of developers like me!

My question is, what is the difference between displaying an image on the screen and on the UITableViewCell in code level? (Do we use UIImageView object in UITableViewCell as well? Do we drag and drop anything? Do we need contentView or subview? etc.)

Was it helpful?

Solution

Have a look at this really nice tutorial. It should not leave any of your questions open.

http://www.markj.net/iphone-asynchronous-table-image/

OTHER TIPS

I don't suggest to follow this approach.A table view has many rows so the image would be too tiny.Do it only if the image are like banners.

Solution

If you still want to upload every image in a different row (so in a cell), you can return a cell with a UIImageWiew inside it:

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

Alternative Solution

If instead you want a big image to be displayed, just monitor the row selection, put a big image well below the table view and change the image well contents when the row selection changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top