views:

54

answers:

1

I have 2 tabs in my TabBar. They both hold instances of the same UITableViewController.

The hierarchy goes UITabbarController > UINavigationController > UITableViewController

From within the tableViewController I'd like to determine which tab is currently selected. I know I can use the selectedIndex property of the UITabBarController I just don't know the easiest way to refer to if from within the current viewController. Do I walk up through the superviews of each view to find the TabBarController?

+1  A: 

If you instantiate and store the UITabBarController in your App Delegate, you can expose it as a property of that object. You can store a static global pointer to your App Delegate object and expose it through a class method:

+ (MyAppDelegate*) instance
{
    return g_Instance;
}

When you need your tabBarController you can use:

[MyAppDelegate instance].tabBarController
Cannonade