【发布时间】:2014-11-25 20:06:03
【问题描述】:
这是我的故事板:
我正在尝试从 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
这是 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
我的主要动机是当调用此方法showFriendReqAlert: 时,第三个标签栏项目Friends 会显示一个红色徽章。但是每当我尝试选择 tabBarItem 时,它会在 NSLog 中显示为 null。
我还尝试了以下方法: self.window.rootViewController.navigationController.tabBarController self.window.rootViewController.tabBarController
但没有任何效果。有什么帮助吗?
谢谢!
【问题讨论】:
-
登录屏幕和标签栏之间的导航控制器的作用是什么?你从登录中使用什么样的segue?您的登录屏幕未嵌入导航控制器中,因此我希望 self.window.rootViewController.navigationController 为零。
-
我也有同样的问题。 RootViewController 是登录屏幕,我想在收到通知后更改徽章。你的问题解决了吗?
标签: ios objective-c iphone xcode5