-1

I have a UITableView which contains five cells. Each cell has a a label and a image. Now using didSelectRowAtIndexPath, when I click on any cell, a new view should appear which contains a label and image from the cell clicked. The code is:

OpenMessageViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"OpenMessageVC"];
    [self.navigationController pushViewController:controller animated:YES];

OpenMessageViewController is my new view that would appear on clicking a cell. I have added a label and image in OpenMessageViewController in storyboard. How do I change the label text and image of OpenMessageViewController to the text and image present in the cell clicked. Thank You

Vamshi Krishna
  • 979
  • 9
  • 19

1 Answers1

0

I haven't put your code in a Xcode project, but couldn't you do something like this to pass the image and text?

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Get the tapped cell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

// Configure the destination VC
UIImageView *myImageView = (UIImageView *)[cell viewWithTag:10]; // Set tag 10 to the UIImageView in your cell
UILabel *myLabel = (UILabel *)[cell viewWithTag:20]; // Set tag 20 to the UILabel in your cell
controller.imageView.image = myImageView.image;
controller.theLabel.text = myLabel.text;

// Navigate
[self performSegueWithIdentifier:@"mySegue" sender:self];
}

Remember to connect the two ViewControllers in IB. You then have to have a label called theLabel and a imageView called imageView on the destination ViewController hooked up to an outlet. (Feel free to change the name)

Erik
  • 2,500
  • 6
  • 28
  • 49
  • You may need to do some tweaking to fit my solution to your "controller" reference. Let me know if you have any questions – Erik Oct 27 '14 at 12:24