1
votes

I've been struggling around for some time with this problem. I got it working but not the way it should and I guess its because Im doing it wrong. My goal is to have the following layout.

I have a Main Menu with four buttons. Clicking on each shows a different TableView (I should have a back button in the right corner of the navController, to be able to go back to the main menu, but I don't). Each of these TableViews are inside a UITabBarController (looks like this http://i.stack.imgur.com/GkFwo.jpg)

So how do I have to do this?

This is my current code (definitely wrong at some point(s))

- (IBAction)MyButton:(id)sender
{
self.tabBarController = [[UITabBarController alloc] init];
UIViewController *viewController1, *viewController2, *viewController3, *viewController4;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    viewController1 = [[[LexikonControllerViewController alloc] initWithNibName:@"LexikonControllerViewController" bundle:nil] setArrays:PflanzenIDs List:ListOfPlants Index:IndexOfPlants dict:DictionaryOfPflantsAndIDs];
}

UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

NSArray* controllers = [NSArray arrayWithObjects:navController1, nil];

self.tabBarController.viewControllers = controllers;

CGRect frame = self.tabBarController.view.frame;
frame.size.height = frame.size.height - 20;
self.tabBarController.view.frame = frame;

[self.view addSubview:self.tabBarController.view];
}

EDIT:

Now I tried this: - (void)applicationDidFinishLaunching:(UIApplication *)application {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

vc = [[MyViewController alloc] init];
[vc setTitle:@"Home"];
[vc setParent:self];

navController = [[UINavigationController alloc] initWithRootViewController:vc];

UITabBarController *tb = [[UITabBarController alloc] init];
NSArray *controllers = [[NSArray alloc] initWithArray:[NSArray arrayWithObjects:navController, nil]];
tb.viewControllers = controllers;

[window addSubview:[tb view]];
[window makeKeyAndVisible];
}

Problem: on the main view (with the main menu) I can see the tab bar (which shouldnt be there) and using hidesBottomBarWhenPushed hides the tabbar completetely on all other views :(

2

2 Answers

1
votes

The tab bar controller should be your root view controller. You could also hook this up within a storyboard.

0
votes

Made it. What I did was set up my Main menu as root view for the navigationcontroller and if I click on one of the buttons I load a new UIViewController which takes care of setting up a TabBarController and load my four different tableviews in each Tab. All of this without storyboard and XIBs.