Access UITabBarController from Appdelegate

I am trying to access my UiTabBarController from a UIViewController which is in a UIWindow,

Since it is not part of the UITabBarController, use self.tabBarController..will not work, since it will be nil.

So, I tried this code:

BBAppDelegate *appDelegate = (BBAppDelegate *)[[UIApplication sharedApplication] delegate];

    UITabBarController *tabBarController = appDelegate.window.rootViewController.tabBarController;

When it goes through the code using the debugger, I see that it appDelegatehas a tabBarController, and it is not zero. However, on the next line

  UITabBarController *tabBarController = appDelegate.window.rootViewController.tabBarController;

This leads to the fact that the tabBarControllercopy has nil value, and tabBarControllerin appDelegatestill has its assigned memory address, not a zero.

What am I doing wrong here?

Edit

Here's what my debugger looks like:

enter image description here Thank you

Edit 2

This is who I am setting up the side menu which is added to rootViewController

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone"
                                                         bundle: nil];

BBFilterViewController *loginController=[[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"FilterViewController"];  UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController];



self.tabBarController = [mainStoryboard instantiateViewControllerWithIdentifier: @"HomeScreen"];

MVYSideMenuOptions *options = [[MVYSideMenuOptions alloc] init];
options.contentViewScale = 1.0;
options.contentViewOpacity = 0.5;
options.shadowOpacity = 0.0;

MVYSideMenuController *sideBarController = [[MVYSideMenuController alloc]initWithMenuViewController:navController contentViewController:self.tabBarController options:options];


self.window.rootViewController = sideBarController;

[self.window.rootViewController addChildViewController:self.tabBarController];

[self.window makeKeyAndVisible];
+4
2

, , :

UITabBarController *tabBarController = (UITabBarController *)appDelegate.window.rootViewController;

//

, :

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController.childViewControllers.lastObject;
+13

, , UITabBarController *tabBarController = appDelegate.tabBarController;

-1

Source: https://habr.com/ru/post/1534059/


All Articles