title: Xamarin, iOS Get Instance of viewcontroller from tabbarcontroller
body: <p>I'm in need of some help.  I'm using Xamarin IOS in Visual Studio 2017 on Windows 10.  I'm using storyboard and I have a tab bar controller with 2 view controllers. My view controllers are A_ViewController and B_ViewController.
  What I would like to do is click a button in A_ViewController that calls an API function in a background thread.  The function periodically return some string that I would like to have displayed in a TextView in B_ViewController.</p>
  
  <p>I have the API callbacks working and can recieve the return strings but I'm not sure how I can get the instance of B_ViewController to update the TextView and display the API return strings.</p>
  
  <p>I know that the tabbarcontroller has a property that contains the instances of all its view controllers because I can change view controllers by calling "this.TabBarController.SelectedIndex = 1;" but from A_ViewController how do I use tabbarcontroller (or any other way) to get B_ViewController's instance?  </p>
  
  <p>I've tried the following from A_ViewController:</p>
  
  <pre><code>    B_ViewController vc = this.TabBarController.ViewControllers[1] as B_ViewController;
      vc.Output_Update("Hello World");  &lt;--- This code creates an exception.
  </code></pre>
  
  <p>My 2 ViewControllers look something like this:</p>
  
  <pre><code>public partial class A_ViewController : UIViewController
  {
      public override void ViewDidLoad(){ 
          base.ViewDidLoad();
          mbtnCallAPI.TouchUpInside += BtnCallAPI_TouchUpInside;
      }
  
      public void BtnCallAPI_TouchUpInside(object sender, EventArgs e) {
          // Call API here.  API Callback will return strings
          // Send return string to B_ViewController's TextView.
      }
  }
  
  
  
  public partial class B_ViewController : UIViewController
  {   
      public void Output_Update(string msg) {
          mTextView.Text += msg;  
      }
  }
  </code></pre>