Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tatsuro-ueda/3331809 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3331809 to your computer and use it in GitHub Desktop.
【テーブル】テーブルセルに画像を表示し、セルをタップすると個別の画像を表示するには

I suppose you just want to select image by table view.

This is selection table view.

selection

And this is detail view.

detail

At first, I made property arrayImg.

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.arrayImg = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"image0.jpg"],
                         [UIImage imageNamed:@"image1.jpg"],
                         [UIImage imageNamed:@"image2.jpg"], nil];
    }
    return self;
}

Then, I wrote the cell selection code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *s = [NSString stringWithFormat:@"image%d.jpg", indexPath.row];
    [self performSegueWithIdentifier:@"showImage" sender:s];
}

At last, I made prepareForSegue method.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DetailViewController *d = segue.destinationViewController;
    d.strImgName = sender;
}

In the detail view, I just wrote below:

- (void)viewWillAppear:(BOOL)animated
{
    self.imageView.image = [UIImage imageNamed:strImgName];
}

The whole project is here:https://github.com/weed/p120801_ImageSelectorWithTableView

You can download sample project and just run it.

I wish my trial is help for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment