0

初めて iPhone アプリケーションを作成しましたが、ビューの切り替えに問題があります。まず、「presentModalViewController:animated:」を介して切り替える 2 つのビュー (ログイン、登録) があります。

しかし、誰かがログインした場合、新しい種類のビューがあるはずです。下部に UITabBar を配置したい (タブ バー コントローラー)。しかし、これはうまくいきません。AppDelegate を必要とするこのようなチュートリアルを使用できるように、新しい AppDelegate を作成しようとしました。

http://www.youtube.com/watch?v=LBnPfAtswgw&feature=player_embedded

新しいコントローラーへの切り替えは、次のように行われます。

startViewController = [[StartViewController alloc] initWithNibName:@"StartView" bundle:nil];
[UIView beginAnimations:@"View Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view addSubview:startViewController.view];
[UIView commitAnimations];

表示されているビューは StartView.xib の UIView であるため、画面は白です。そこに、新しい AppDelegate、File's owner、View、TabBarController があります。ただし、UIView のみが読み込まれ、TabBarController は読み込まれません。

どうすればこの問題を解決できるか分かりますか?

感謝をこめて。

4

1 に答える 1

3

TabBarControllerから始めることをお勧めします。ユーザー名/パスワードが設定されていない場合、アクティブなViewControllerはpresentModalViewController:animated:を実行して、ログイン/登録のviewsControllerをモーダルモードで表示します(下にあるTabBarControllerを非表示にします)。

これをプログラムで実行するためのサンプルコードを次に示します。

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
 [window setBackgroundColor:[UIColor whiteColor]];

 tabBarController = [[UITabBarController alloc] init];


 aViewController = [[aViewController alloc] init];
 UINavigationController *aNavController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
 aNavController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
 [aViewController release];

 tabBarController.viewControllers = [NSArray arrayWithObjects: aNavController, nil];

 // Add the tab bar controller's current view as a subview of the window
    [window addSubview:tabBarController.view];

 if(userNotLoggedIn){
     [self displayLoginViewController];
 }


    [window makeKeyAndVisible];
}

- (void)displayLoginViewController {
 LoginViewController *controller = [[LoginViewController alloc] init];
 // setup controller
 [self.tabBarController presentModalViewController:controller animated:NO];
 [controller release];
}
于 2009-12-15T14:44:31.957 に答える