Chris
Chris

Reputation: 1034

UITabBars doesn't recognize the navigation bar and Navigation bar hiding table view controller

I have a view controller inside a navigation bar that pushes a tab bar view controller which has 4 tabs and view controllers to go with it. When I NSLog(@"%@", self.navigationController) inside TabBarViewController's viewDidLoad it comes up as (null). Even NSLog(@"%@",self.tabBarController) is (null) inside TabBarViewController's viewDidLoad. It is weird because I have a selector, for the back button, called dismissTab and I pop the view controller and it works. If I NSLog there it doesn't come up as (null) so something is wrong somewhere. I have a feeling that this is the reason that my ViewControllers, for each of the tabs, is being hidden by the NavigationBar and TabBar. I have read posts about NavigationBar/TabBars hiding/covering a part of a controller but all of them just find a hack to resize the table view or more the objects down/up. I want to find a solution.

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIStoryboard *iPhoneStoryBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    ViewController *mainViewController = (ViewController*)[iPhoneStoryBoard instantiateViewControllerWithIdentifier:@"HomePage"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];

    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

ViewController.m when I push the tabBars

UIStoryboard *iPhoneStoryBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
        GRxTabBarViewController *tabViewController = (GRxTabBarViewController*) [iPhoneStoryBoard instantiateViewControllerWithIdentifier:@"GRxTabBarViewController"];

PViewController *pController = [tabViewController.viewControllers objectAtIndex:0];
SViewController *sController = [tabViewController.viewControllers objectAtIndex:1];
IViewController *iController = [tabViewController.viewControllers objectAtIndex:2];
MViewController *mController = [tabViewController.viewControllers objectAtIndex:3];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:iController];

[tabViewController setViewControllers:[NSArray arrayWithObjects:pController, sController, navController, mController, nil]];
[self.navigationController pushViewController:tabViewController animated:YES];

I don't know where I could have gone wrong because in GRxTabBarViewController's viewDidLoad I set an image for the back button and a selector and it works because the Image is Set and the selector pops it off the stack. Also I can load data and do things in the pViewController, iViewController, sViewController, and mViewController.

Anyone have this problem or know of a solution they can direct/guide me to? Anything helps to be honest. Thanks in advance!

Upvotes: 0

Views: 132

Answers (2)

CodeHelp
CodeHelp

Reputation: 1328

If you want to log your navigationController and tabBarController, you should do it in (void)viewWillAppear:(BOOL)animated and not inside (void)viewDidLoad.

Upvotes: 0

Subzero
Subzero

Reputation: 961

It looks like you are using Storyboard to hook up a tab bar controller inside a navigation controller. I think Storyboard allows you to do that, but I am not sure whether it's the standard way of doing it- unless you have a very compelling/impossible-to-do-otherwise requirement, you should always be able to use a tab bar controller as the holding controller for switching views and then put your navigation controllers as root view controllers in any of the tab bar views. I suggest you look at the possibility of changing your controller hierarchy implementation. That seems feasible looking at your code- AppDelegate.m and the ViewController.m code snippets.

Upvotes: 1

Related Questions