这是我的故事板:

我试图从AppDelegate.m内的方法访问tabBarController
这是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
Run Code Online (Sandbox Code Playgroud)
这是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
Run Code Online (Sandbox Code Playgroud)
我的主要动机是当showFriendReqAlert:调用此方法时,会向第三个标签栏项目显示红色徽章Friends.但每当我尝试选择tabBarItem时,它在NSLog中都显示为null.
我还尝试了以下内容:self.window.rootViewController.navigationController.tabBarController self.window.rootViewController.tabBarController
但没有任何作用.有帮助吗?
谢谢!