Macness
Macness

Reputation: 1226

Looking to create UINavigationView or UITableView in an existing UITabBarController

So I used the template of a UITabBarController application to create an app and I find my self in a situation I can't solve. I'm looking to create my last view (viewcontroller4 instance with the FourthViewController class) to actually be a UITableViewController/UITableView/or UINavigationController. I can't really tell which will be best for what I need.

Basically it should an info screen, with a tableview, that you can tap a cell and select a different view (Settings, About the application, Help, Email for Support). Any ideas on how to impliment this? I've tried to substitue a UINavigation controller for the UIViewController listed (viewcontroller4).

below is my appdelegate.m code for reference:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2, *viewController3, *viewController4;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
    viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
    viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPhone" bundle:nil];
    viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController_iPhone" bundle:nil];
} else {
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil];
    viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil];
    viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPad" bundle:nil];
    viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;}

Upvotes: 0

Views: 203

Answers (1)

XJones
XJones

Reputation: 21967

Not sure how you tried to create the UINavigationController but it will work fine. After you create your viewControllers, do the following:

UINavigationController *navController = [[UINaviagtionController alloc] initWithRootViewController:viewController4];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, navController, nil];
// rest of your code

Upvotes: 1

Related Questions