0

I started a project in Xcode 4.2 using tab view template. In the app delegate I added a third tab by code just like first and second tabs. Then I created a third view controller class with a nib file.
When I run this app, I see all three tabs but when I click on the third tab, it crashes. I noticed the first and second nib files have a dark bar at the bottom(probably representing the tab bar) of the view but the new third nib file that I created lacks it. Any idea how I make this third tab work?

Thanks

This is how I add the third view controller.

- (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;
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];
} else {
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil];
    viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1,  viewController2, viewController3, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
saman01
  • 924
  • 4
  • 12
  • 25
  • probably you need to take care of the memory. And to show us some code. A plus would be to print the crash message too. –  Dec 22 '11 at 19:06
  • There is no error generated in output. The last words on output screen is: Current Language: auto; currently objective-c (gdb) – saman01 Dec 22 '11 at 19:24

1 Answers1

0

In the tab bar controller make sure the class of the view controller for the tab is the same as the view controller class you created.

Also check the logs, it will probably have a very informative message for you as to why it crashed.

Edit:

Never mind, you are passing in an un-initialized view controller for viewController3. Set all of those initial values to nil.

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • All classes are the same. and the log file is empty. It contains only the initialization messages. – saman01 Dec 22 '11 at 19:31