Reputation: 509
I just can't for the life of me get a navigation controller (and bar) in each of my tab bar item views. Here is my appdelegate , what am I missing? FrontPage
and Opinion
are tableviewcontrollers as well, just forgot the table in their names.
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FrontPageViewController *frontPageVC = [[FrontPageViewController alloc] initWithNibName:nil bundle:nil];
frontPageVC.title = @"Front Page";
frontPageVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *frontPageNavController = [[UINavigationController alloc] initWithRootViewController:frontPageVC];
CampusTableViewController *campusVC = [[CampusTableViewController alloc] initWithNibName:nil bundle:nil];
campusVC.title = @"Campus";
campusVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *campusNavController = [[UINavigationController alloc] initWithRootViewController:campusVC];
OpinionViewController *opinionVC = [[OpinionViewController alloc] initWithNibName:nil bundle:nil];
opinionVC.title = @"Opinion";
opinionVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *opinionNavController = [[UINavigationController alloc] initWithRootViewController:opinionVC];
SportsTableViewController *sportsVC = [[SportsTableViewController alloc] initWithNibName:nil bundle:nil];
sportsVC.title = @"Sports";
sportsVC.tabBarItem.image = [UIImage imageNamed:@"second"];
UINavigationController *sportsNavController = [[UINavigationController alloc] initWithRootViewController:sportsVC];
PDFViewController *pdfVC = [[PDFViewController alloc] initWithNibName:nil bundle:nil];
NSArray *controllers = [NSArray arrayWithObjects:frontPageVC, campusVC, opinionVC, sportsVC, pdfVC, nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
[[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];
}
thank you!
edit: apparently I need to type more to explain my problem because SO won't let me post without a certain amount of words?
Upvotes: 0
Views: 2521
Reputation: 287
Why did you give this method after return statement?
[[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];
Try give this before return statement or remove this statement. Because u returning next line won't execute. Also let us know your problem clearly. What you are trying to do.
Upvotes: 0
Reputation: 809
Change this line
NSArray *controllers = [NSArray arrayWithObjects:frontPageVC, campusVC, opinionVC, sportsVC, pdfVC, nil];
to that
UINavigationController *pdfNavController = [[UINavigationController alloc] initWithRootViewController:pdfVC];
NSArray *controllers = [NSArray arrayWithObjects:frontPageNavController, campusNavController, opinionNavController, sportsNavController, pdfNavController, nil];
Upvotes: 2
Reputation: 3975
Your controllers
should include the navigation controllers, not the individual controllers.
NSArray *controllers = [NSArray arrayWithObjects:frontPageNavController, campusNavController, opinionNavController, sportsNavController, pdfNavController, nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
// you can remove the last line: [[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];
Apple said in a document (can't remember if in the Human Interface Guidelines, in View Controller Programming, Tab Bar Controller Programming, or Navigation Controller Programming) that if you want to have navigation controllers and tab bar controllers, you must put the navigation controllers inside the tab bar controller.
Upvotes: 0