在您的代码中,我将self.window.rootViewController 更改为App Delegate。
我也改成SlideNavigationController 定义新的UINavigationController 然后让Storyboard Id 访问下面的代码。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
bundle: nil];
self.landingScreen = (SlideNavigationController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"launchingNVCtr"];
还有一些代码更改为appDelegate。
-(void)setupDrawers{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
bundle: nil];
self.landingScreen = (SlideNavigationController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"launchingNVCtr"];
LeftMenuViewController *leftMenu = (LeftMenuViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"LeftMenuViewController"];
RightMenuViewController *rightMenu = (RightMenuViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"RightMenuViewController"];
self.landingScreen = [SlideNavigationController sharedInstance];
self.landingScreen.rightMenu = rightMenu;
self.landingScreen.leftMenu = leftMenu;
self.landingScreen.menuRevealAnimationDuration = 0.18f;
// Creating a custom bar button for right menu
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[button setImage:[UIImage imageNamed:@"gear"] forState:UIControlStateNormal];
[button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.landingScreen.rightBarButtonItem = rightBarButtonItem;
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *menu = note.userInfo[@"menu"];
NSLog(@"Closed %@", menu);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *menu = note.userInfo[@"menu"];
NSLog(@"Opened %@", menu);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *menu = note.userInfo[@"menu"];
NSLog(@"Revealed %@", menu);
}];
}
然后点击Log In按钮时调用如下方法。
-(void)displayLandingScreen{
[self setupDrawers];
self.window.rootViewController = self.landingScreen;
}
用户点击Log out时的以下代码。
-(void)logOutPressed{
//mainTabBar
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
bundle: nil];
UITabBarController *loginTab = (UITabBarController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"mainTabBar"];
self.window.rootViewController = loginTab;
}
Also same code retrieve from the HERE.