开发者

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

开发者 https://www.devze.com 2023-01-09 13:48 出处:网络
I have 2 tabs in my TabBar.They both hold instances of the same UITableViewController. The hierarchy goes

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

精彩评论

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

关注公众号