0

I am rather new at Objective C programming so pardon me if the info in the question is not sufficient for answering.

Basically this is my situation: I have a View Controller with a UITableView where each cell is filled with an image and text. What I want to do is: When I click on one of the cells I want to direct the application to another View Controller (I have made this View Contoller) and also want to send the image and text included in the cell so that the new View Controller knows about this information.

I am able to create a link between the cell and the View Controller by "drag-drop" in the Storyboard, but I am not able to send any information over.

Does anyone have a quick step by step guide on how to do this?

Really appreciate any answer, and sorry again if the question either includes insufficient info or something.

Best regards, Me

  • I think you had given segue connection to other view controller. You can able to do one thing give that connection to table view and send data normally from one view controller to other view controller – Romance Apr 01 '14 at 13:04
  • This was the first result from google search : http://stackoverflow.com/questions/7864371/ios-how-to-pass-prepareforsegue-an-object – wootage Apr 01 '14 at 13:07
  • @user3485173 have you created a class for your second viewController – odukku Apr 01 '14 at 13:10
  • 1
    I'd suggest reading Apple's "Start Developing iOS Apps Today" guide. It walks you through the process of building a simple To Do List app while explaining concepts. Once completed, you'll understand how to do this and have a better understanding of the concepts you need to understand (Push Segues, Table View data source methods, sending data in prepareForSegue, etc) https://developer.apple.com/library/iOS/referencelibrary/GettingStarted/RoadMapiOS/index.html – huwiler Apr 01 '14 at 13:15
  • hi and thanks for nice comments. I have created a class for the other ViewController called PersonViewController. – user3485173 Apr 01 '14 at 13:20

1 Answers1

0

It's quite simple.

You just need to implement the method

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

Your sender object will be the selected cell. So, you will have something like:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
 if ([segue.identifier isEqualToString:@"SegueIdentifier"])
 {
     UITableViewCell *cell = (UITableViewCell *)sender;

     UIViewController *destinationController = segue.destinationViewController;

     destinationController.image = cell.imageView.image;
     destinationController.text = cell.textLabel.text;
 }
}
Andrei Filip
  • 1,145
  • 15
  • 33