title: Passing data between viewcontrollers in xamarin.ios
body: <p>I am developing an iPhone app in Xamarin.iOS (C#) and I am stuck at passing variables between ViewControllers (I am using storyboards).</p>
  
  <p>General layout of my app is listed below: </p>
  
  <pre><code>LoginViewController --&gt; TabViewController --&gt; NavigationController --&gt; MainViewController
  </code></pre>
  
  <h3>SCREEN SHOT ADDED:</h3>
  
  <p><a href="https://i.stack.imgur.com/DepvN.jpg" rel="nofollow noreferrer">Overview of my Storboard - Explains what I want to do:</a></p>
  
  <p>What I would like to do is when user' credentials successfully validated at the "<strong>LoginViewController</strong>", the app will take user to "<strong>MainViewController</strong>". </p>
  
  <p>I also want to pass a variable (let's say 'userName') from "<strong>LoginViewController</strong>" to "<strong>MainViewController</strong>". However, I got no luck. </p>
  
  <p>I posted my code below. It is working (passes variable) but the problem is that since we are pushing directly from <strong>LoginView</strong> to <strong>MainView</strong>, Tabbar and Navigation Bar do not shown anymore. </p>
  
  <p>What are the best practices for passing data between ViewController if <strong>tabViewController</strong> exists?  </p>
  
  <pre><code>// Instantiating the MainViewController
  MainViewController controller = this.Storyboard.InstantiateViewController("MainViewController") as MainViewController;
  
  //Here I pass the data from the LoginViewController to the MainViewController
  controller.userName= this.userName;
  
  // Show the MainViewController
  this.NavigationController.PushViewController(controller , true);
  </code></pre>
  
  <p>Any suggestions will be appreciated! </p>