title: Getting the selectedIndex of the currently selected tab from a viewcontroller
body: <p>I currently have an iPhone application with a tabbar and multiple viewcontrollers. All the views are designed in Interface Builder. I'd like to be able to get the currently selected index of the tabbar from the viewcontroller, but for some reason this property returns (null).</p>
  
  <p>I called the following in the viewDidLoad function of my viewcontroller:</p>
  
  <p><code>    self.tabBarController.selectedIndex</code></p>
  
  <p>What would be the correct way to do this?</p>
  
  <p>Updated with the code of the AppDelegate class.</p>
  
  <p>MyAppDelegate.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface MyAppDelegate : NSObject &lt;UIApplicationDelegate, UITabBarControllerDelegate&gt; {
    UIWindow *window;
    UITabBarController *tabBarController;
  }
  
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
  
  @end
  </code></pre>
  
  <p>MyAppDelegate.m:</p>
  
  <pre><code>#import "MyAppDelegate.h"
  
  @implementation MyAppDelegate
  
  @synthesize window, tabBarController;
  
  - (void)applicationDidFinishLaunching:(UIApplication *)application {
    [window addSubview:tabBarController.view];
  }
  
  - (void)dealloc {
      [tabBarController release];
      [window release];
      [super dealloc];
  }
  
  @end
  </code></pre>