title: Pass a value from one ViewController to another in Objective-C
body: <p>I'm fairly new to Objective-C, programming. The one thing, I'm currently putting up with is passing a value from the first <code>ViewController</code> to the next one.</p>
  
  <p>I've read <a href="https://stackoverflow.com/a/9736559/2823419">this entry here</a> and it didn't help me. Which is funny, since his answer has nearly 500 votes, so I must be the problem. What I did was the following.</p>
  
  <p>I opened my <code>PreviewViewController.m</code> and added the following line <code>#import "MainViewController.h"</code> since I wanted to pass a value from the <code>PreviewViewController</code> to the `MainViewController. Then, when I switch the layouts ( which successfully works ) I want to pass a value.</p>
  
  <pre><code>MainViewController  *mainViewController     = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
  mainViewController.userId                   = @"539897197";
  </code></pre>
  
  <p>As you can see, I want to pass the userId. For that, I also created a property in the <code>MainViewController.h</code></p>
  
  <pre><code>@property ( nonatomic, strong ) NSString *userId;
  </code></pre>
  
  <p>Now, In my <code>MainViewController.m</code> I want to access the userId. But when I log it, the console tells me it is <code>null</code>. However, when I set the variable right before the <code>NSLog</code> it works, so it seems like the passing is the problem.</p>
  
  <p>Additionally in the <code>MainViewController.m</code> I have the following line</p>
  
  <pre><code>@synthesize userId = _userId; 
  </code></pre>
  
  <p>but even when I removed that line and changed the <code>NSLog</code> to <code>NSLog(@"%@",self.userId);</code> the same problem occurred. </p>
  
  <p>How can I successfully pass the variables? Which step am I doing wrong?</p>
  
  <p><strong>EDIT</strong>
  This is how I switch the layouts</p>
  
  <pre><code>UIViewController    *viewController         = [[MainViewController alloc]init];
  MainViewController  *mainViewController     = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
  mainViewController.userId                   = @"539897197";
  [self presentViewController:viewController animated:YES completion:NULL];
  </code></pre>