开发者

Determining the currently selected TabBarItem from within a tableViewController on the iPhone?

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 th开发者_如何学Gorough the superviews of each view to find the TabBarController?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜