Navigation bar not accessible when using SWRevealViewController with UITabBarController

102 Views Asked by At

I have set Sliding menu(Rear view controller) using SWRevealViewController with a UITabBarController (front view controller). Below is the piece of code I used:

RearMenuViewController *rearViewController = [[RearMenuViewController alloc] init];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

UINavigationController *navTabController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];


SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:navTabController];
revealController.delegate = self;
revealController.rightViewController = nil;
self.viewController = revealController;

self.window.rootViewController = revealController;

This works fine and I can toggle between the rear menu and tab bar items using swipe gesture.

But I am not able to set the navigation title for each tab bar item nor I can add any bar button on navigation bar. I can only see blank navigation bar for every tab bar item.

Also would like to share that I am NOT using storyboard in the project.So, I need to set the title and a bar button through code only.

Please let me know if any other info is required.

1

There are 1 best solutions below

0
Nipun Arora On

I managed to access the navigation bar for each tab bar item like this:

UINavigationController *currentNav = (UINavigationController *)self.tabBarController.parentViewController;

UINavigationItem *navItem =(UINavigationItem *) [currentNav.navigationBar.items firstObject];
navItem.title = @"Dashboard";

Need to write this in each item (view controller) of tab bar if we need to have different titles for each tab bar item.

Please let me know if there is a better way to achieve this.