This is my storyboard:

I am trying to access tabBarController from a method inside AppDelegate.m
This is AppDelegate.h:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import "STAlertView.h"
@interface demo_AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) STAlertView *av;
@end
And this is AppDelegate.m:
#import "demo_AppDelegate.h"
#import "demo_Friends_ViewController.h"
@implementation demo_AppDelegate
-(void)showFriendReqAlert:(NSNotification *)pNotification{
NSLog(@"Hello from showFriendReqAlert:");
NSLog(@"Root: %@", [self.window.rootViewController.navigationController.tabBarController viewControllers]);
}
....
....
....
....
@end
My main motive is when this method showFriendReqAlert: is called, a red badge is shown to the third tab bar item which is Friends. But whenever i try to select tabBarItem, it says null in NSLog.
I have also tried the following: self.window.rootViewController.navigationController.tabBarController self.window.rootViewController.tabBarController
but nothing works. Any help?
Thanks!
I believe (sorry for believing here ;-) that the
TabBarControllershould be your first controller and yournavigationBarControllermust come afterwards as it does not make much sense for the navigationController (if you change a tab) what to push/pop.I suggest that you remove your first
DemoViewControllerand followingNavigationControllerand that your first Controller is yourTabBarController(simply set "Is Initial View Controller" in IB).Then you can access your
tabBarlike this:Swift 5: