侧面导航点击不起作用
Side Navigation Click Not Working
我已经从库 iOS Slide Menu 中实现了这个滑动菜单并使用了 uitabbarcontroller。
主页 viewcontroller 有此幻灯片菜单,但在单击侧导航栏时会出现滑动栏菜单,但在单击记录时不会发生任何操作。而如果我在没有 tabbarcontroller 的情况下使用这个 slidemenu,它就可以正常工作。
任何人如果在 IOS 中使用 objective C 使用故事板在 uitabbarcontroller 下实现了这个滑动菜单。请分享您的答案。
在您的代码中,我做了一些更改,例如 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;
}
我已经从库 iOS Slide Menu 中实现了这个滑动菜单并使用了 uitabbarcontroller。
主页 viewcontroller 有此幻灯片菜单,但在单击侧导航栏时会出现滑动栏菜单,但在单击记录时不会发生任何操作。而如果我在没有 tabbarcontroller 的情况下使用这个 slidemenu,它就可以正常工作。
任何人如果在 IOS 中使用 objective C 使用故事板在 uitabbarcontroller 下实现了这个滑动菜单。请分享您的答案。
在您的代码中,我做了一些更改,例如 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;
}