0

I am trying to include a navigation controller within the third tab of my tabbarcontroller. I have had some feedback but am only able to get about this far. The code below doesn't produce any errors, but does not seem to work as the app just quits out. Does anyone have any input on what I might be doing wrong?

UIViewController *viewController1 = [[FirstViewController alloc] 
initWithNibName:@"PDCFirstViewController" bundle:nil];

UIViewController *viewController2 = [[SecondViewController alloc] 
initWithNibName:@"SecondViewController" bundle:nil];

viewController3 = [[UIViewController alloc] initWithNibName:@"ThirdViewController" 
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc] 
initWithRootViewController:viewController3];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray 
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];

Thank you all!

int main(int argc, char *argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([PDCAppDelegate class]));
}
}
Brandon
  • 2,163
  • 6
  • 40
  • 64
  • AFAIK that looks ok so far. – Hermann Klecker Dec 12 '12 at 08:36
  • Where exactly do you get the crash? What does the crashlog look like? – Hermann Klecker Dec 12 '12 at 08:36
  • @HermannKlecker, I get the crash right when the app starts up. I have updated my question to show the error. – Brandon Dec 12 '12 at 08:40
  • What else does the debugger say? Did you try setting an All-Exceptions break point? (If so then you might click on continue some times before the actual error message is printed to the debug console) – Hermann Klecker Dec 12 '12 at 08:59
  • Hi @HermannKlecker, I no longer have the crashing, but now my app just opens up to a blank screen. I have created a new question here: http://stackoverflow.com/questions/13836189/app-opening-to-blank-black-screen Any guidance would be great! Thank you! – Brandon Dec 12 '12 at 09:04
  • Do you want the tabBarController to be the rootViewController? If so, do you set the same in applicationDidFinishLaunching: as self.window.rootViewController = self.tabBarController;?? – Divya Dec 12 '12 at 10:29

2 Answers2

0

Make sure with all nib names you are using and also with class name, i.e. if you class name of UIViewController is FirstViewController, nib name should be same. And you have used "PDCFirstViewController" for nib name. Same with ThirdViewController & SecondViewController.

Try below code...

FirstViewController *viewController1 = [[FirstViewController alloc] 
initWithNibName:@"FirstViewController" bundle:nil];

SecondViewController *viewController2 = [[SecondViewController alloc] 
initWithNibName:@"SecondViewController" bundle:nil];

ThirdViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" 
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc] 
initWithRootViewController:viewController3];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray 
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
alloc_iNit
  • 5,173
  • 2
  • 26
  • 54
  • Hi, thanks for the input but I am still getting the same issue – Brandon Dec 12 '12 at 08:48
  • Have you check all nib names and defined controller classes? And also make sure about IBOutlet you have set in xibs. – alloc_iNit Dec 12 '12 at 08:51
  • OK after following your advice I no longer have the crash, but I just see a blank black screen when the app loads up. Any ideas? – Brandon Dec 12 '12 at 08:52
  • Strictly spoken there is no need to name the nib files the same as the view controller subclass. There may not even a need for a dedicated subclass of uiviewcontroller if uiviewcontroller suffices for a start. – Hermann Klecker Dec 12 '12 at 09:02
0

Here is the solution

UIViewController *courseView = [[[CoursesView alloc] initWithNibName:@"CoursesView" bundle:nil] autorelease];
UIViewController *subjectViewController = [[[SubjectViewController alloc] initWithNibName:@"SubjectViewController" bundle:nil] autorelease];
UIViewController *videoViewController = [[[VideoViewController alloc] initWithNibName:@"VideoViewController" bundle:nil] autorelease];
UIViewController *quizViewController = [[[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil] autorelease];
UIViewController *proifileViewController = [[[Profile2ViewController alloc] initWithNibName:@"Profile2ViewController" bundle:nil] autorelease];

UINavigationController *coursNav = [[UINavigationController alloc] initWithRootViewController:courseView];
UINavigationController *subjectNav = [[UINavigationController alloc] initWithRootViewController:subjectViewController];
UINavigationController *videoNav = [[UINavigationController alloc] initWithRootViewController:videoViewController];
UINavigationController *quizNav = [[UINavigationController alloc] initWithRootViewController:quizViewController];
UINavigationController *profileNav = [[UINavigationController alloc] initWithRootViewController:proifileViewController];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[coursNav, subjectNav,videoNav,quizNav,profileNav];
self.tabBarController.navigationController.navigationBarHidden=YES;
self.tabBarController.delegate=self;
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];

it works for me

Yashesh
  • 1,799
  • 1
  • 11
  • 29