I am trying to do the following:
- Show a launch page in the app.
- Try to log in user by pinging my website. If user is logged in, transition to a tab controller with 3 tabs and navigation controller for each tab.
- If user is not logged in, transition to tab controller with 3 tabs but each tab brings the user to different pages (login, register, learn more)
How can I add a tab controller in the view controller and not in the app delegate?
I was going to do the following
in the app delegate set the rootController to be viewcontroller1
UIViewController * viewController1;
viewController1 = [[HTLoginViewController alloc] initWithNibName:@"HTLoginViewController_iPhone" bundle:nil];
self.window.rootViewController = viewController1;
Then in viewcontroller1 call the setTab function below
-(void)setTab { self.tabBarController = [[UITabBarController alloc] init];
UIViewController * viewController1, *viewController2, *viewController3;
viewController1 = [[HTMyJobsViewController alloc] initWithNibName:@"HTMyJobsViewController" bundle:nil];
viewController2 = [[MTViewController alloc] initWithNibName:@"MTViewController" bundle:nil];
viewController3 = [[HTInviteController alloc] initWithNibName:@"HTInviteController" bundle:nil];
viewController1.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
// account view
UINavigationController * firstNavController = [[UINavigationController alloc]initWithRootViewController: viewController1];
viewController2.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2];
// book view
UINavigationController * secondNavController = [[UINavigationController alloc]initWithRootViewController: viewController2];
viewController3.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3];
// invite view
UINavigationController * thirdNavController = [[UINavigationController alloc]initWithRootViewController: viewController3];
CATransition *transition = [CATransition animation];
transition.duration = 0.7f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[firstNavController.view.layer addAnimation: transition forKey:nil];
[secondNavController.view.layer addAnimation: transition forKey:nil];
[thirdNavController.view.layer addAnimation: transition forKey:nil];
self.tabBarController.viewControllers = [[NSArray alloc] initWithObjects: firstNavController, secondNavController, thirdNavController, nil];
self.tabBarController.delegate = self;
self.tabBarController.selectedIndex = 1;
HTAppDelegate*appDelegate = (HTAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.serivceImg=[[UIImageView alloc]initWithFrame:CGRectMake(0, appDelegate.window.frame.size.height - 66, 108, 58)];
appDelegate.serivceImg.image=[UIImage imageNamed: @"tabi_01.png"];
appDelegate.contactImg=[[UIImageView alloc]initWithFrame:CGRectMake(108, appDelegate.window.frame.size.height - 66, 107, 58)];
appDelegate.contactImg.image=[UIImage imageNamed: @"tabi_02.png"];
appDelegate.bookingImg=[[UIImageView alloc]initWithFrame:CGRectMake(215, appDelegate.window.frame.size.height - 66, 105, 58)];
appDelegate.bookingImg.image=[UIImage imageNamed: @"tabi_03.png"];
[ self.tabBarController.view addSubview: appDelegate.serivceImg];
[ self.tabBarController.view addSubview: appDelegate.contactImg];
[ self.tabBarController.view addSubview: appDelegate.bookingImg];
self.tabBarController.tabBar.frame = CGRectMake(0, appDelegate.window.frame.size.height - 45, 320, 45);
[self.view addSubview: self.tabBarController.view];
What's the best way to get this done?