简体   繁体   中英

Reference to the current tab in storyboard UITabBarController

I added the following code in my AppDelegate application didFinishLaunchingWithOptions to make reference to the UITabBarController I've created in storyboard (like the Tabbed Application template). Then I want self.currentController reprecent the current tab (ViewController). I can make it reprecent one of the tabs like this and get name of that ViewController for self.currentController in Log:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
self.currentController = [[tabController viewControllers] objectAtIndex:0];
}

But how to make it reprecent the currently dislplayed tab?

I've tried:

self.currentController = tabController.selectedViewController 

I get warning: Incompatible pointer assigning to UIViewController<BannerViewContainer> from UIViewController. If I NSLog self.currentController now it says (null).

I've also tried different combinations of code from the UITabBarController class reference but I can't make it work. What's the right code for this?

您正在寻找tabController.selectedViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM