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

別の構造でこれを試してみます。まず、アプリデリゲートにタブバーコントローラーとその3つのコンテンツコントローラーを作成し、ウィンドウのルートビューコントローラーにします。最初のタブのコントローラーで、viewDidAppearAnimated:メソッドで起動ページをモーダルに表示します。これにより、そのビューが最初に表示されます(animateがNOに設定されている場合)。ログインが成功した場合は、モーダルビューコントローラを閉じるだけで、準備が整います。ログインに失敗した場合は、3つの新しいコンテンツコントローラーを作成し、それらをタブバーコントローラーのviewControllersプロパティに設定してから、モーダルを閉じます。このように、必要なのは1つのタブバーコントローラーだけです。これは、より一般的なセットアップであるルートビューコントローラーです。

于 2012-12-05T17:31:45.190 に答える