我正在尝试执行以下操作:
- 在应用程序中显示启动页面。
- 尝试通过 ping 我的网站来登录用户。如果用户已登录,则转换到具有 3 个选项卡和每个选项卡的导航控制器的选项卡控制器。
- 如果用户未登录,则转换到具有 3 个选项卡的选项卡控制器,但每个选项卡将用户带到不同的页面(登录、注册、了解更多)
如何在视图控制器中而不是在应用程序委托中添加选项卡控制器?
我打算做以下事情
在应用程序委托中将 rootController 设置为 viewcontroller1
UIViewController * viewController1;
viewController1 = [[HTLoginViewController alloc] initWithNibName:@"HTLoginViewController_iPhone" bundle:nil];
self.window.rootViewController = viewController1;
然后在 viewcontroller1 调用下面的 setTab 函数
-(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];
完成这项工作的最佳方法是什么?