0

Xcode 4.3 にタブ バー アプリケーションがあり、タブバーが表示される前にログイン画面を挿入しようとしています。アプリは正常に動作しますが、アニメーションがない場合はビューが表示されませんpresentModalViewControlleranimated:YES

@synthesize window = _window;

@synthesize tabBarController = _tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController = self.tabBarController;

    LogInViewController *logViewController = [[LogInViewController alloc] initWithNibName:@"LogInViewController" bundle:nil];
    [self.window addSubview:_tabBarController.view];

    [self.tabBarController presentModalViewController:logViewController animated:YES];
    //This wont work
    //[self.tabBarController presentModalViewController:logViewController animated:NO];

    [self.window makeKeyAndVisible];
    return YES;

}

-(void)loginDone{

    NSLog(@"back to the app delegate");
   [self.tabBarController dismissModalViewControllerAnimated:YES];


}
  1. これは正しい方法ですか?
  2. コードが で動作しないのはなぜanimated:NOですか?
  3. これも output で取得しますUnbalanced calls to begin/end appearance transitions for <UITabBarController: 0x689d350>
4

2 に答える 2

1

まず、[self.window makeKeyAndVisible];View Controller のセットアップの前に移動します。

viewWillAppear:さらに、ログイン画面を表示する前にアプリのビュー階層が完全に初期化されていることを確認するために、最初に表示されるビュー コントローラーのメソッド内でモーダル ビュー コントローラーを表示する必要があります。

于 2012-06-05T12:36:05.577 に答える
1

これをしないでください:

[self.window addSubview:_tabBarController.view];

これを行う:

self.window.rootViewController = _tabBarController;

これtabBarControllerで画面に表示されます。しかし、それはまさにあなたが望むものではありません...私のアドバイスは次のとおりです。

1)上で示しlogViewControllerたように、hasを配置することから始めrootViewControllerます。

2) 必要なものを取得したら (ログインに成功)、AppDelegate にrootViewController. これは、委任または通知で行うことができます。

また、Toastor が間接的に指摘したように、presentViewController は、UIViewController(AppDelegate からではなく) 実際に開始した人から開始する必要があります。

于 2012-06-05T12:38:07.900 に答える