0

我正在尝试执行以下操作:

  1. 在应用程序中显示启动页面。
  2. 尝试通过 ping 我的网站来登录用户。如果用户已登录,则转换到具有 3 个选项卡和每个选项卡的导航控制器的选项卡控制器。
  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];

完成这项工作的最佳方法是什么?

4

1 回答 1

0

我会尝试使用不同的结构。首先,在应用委托中创建标签栏控制器及其三个内容控制器,并使其成为窗口的根视图控制器。在第一个选项卡的控制器中,在 viewDidAppearAnimated: 方法中模态显示您的启动页面——这将使该视图成为第一个被看到的视图(如果您将动画设置为 NO)。如果登录成功,只需关闭模态视图控制器,就可以开始了。如果登录失败,创建 3 个新的内容控制器,将它们设置为标签栏控制器的 viewControllers 属性,然后关闭模式。这样,您只需要一个标签栏控制器,它是根视图控制器,这是更常见的设置。

于 2012-12-05T17:31:45.190 回答