how to pass data from table view to second view controller?

How can I pass the data/information from one view controller to another in storyboard?

  • I'm using iOS 6.1 and X-code 4.5 so I'm not using *.xib file for view. I'm a beginner and want to make a app in which user will enter his name  in main/initial view and then in 2nd view there will be a label in which I will print "Hello USER_NAME". I have made GUI for both views and also I have 2-2 separate files (*.h ,*.m) for both views . till now i can enter the name but 2nd view is not getting that information? suggest simplest way to do this.

  • Answer:

    Consider two viewcontrollers, ViewController1 and ViewController2 Create a @property in ViewController2, @property (copy, nonatomic) NSString * stringForVC2; import ViewController2.h in the ViewController1.m file when you are presenting the ViewController2 using the below method - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{  if([segue.identifier isEqualToString:@"YOUR_SEGUE_IDENTIFIER"]) {  ViewController2 *controller = (ViewController2 *)segue.destinationViewController;         controller.stringForVC2 = @"YOUR_STRING_HERE"; // here you have passed the value //  } } You can pass strings, numbers etc the same way. Hope it helped.

Shrutesh Sharma at Quora Visit the source

Was this solution helpful to you?

Other answers

Go through this video u will get all idea about flow, and passing value between view controllers

Asad ali Govani

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.