0

私はすでにUINavigationControllerのアプリケーションを持っていますが、UITabBarControllerに切り替える必要があります。問題は、UItabが最初から切り替わっても動作しないため、デリゲートメソッドで切り替えることですどちらもうまくいかない! アプリケーションのすべてのコードデリゲートルートビューコントローラを切り替える

self.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]]; 
    self.tabBarController = [[UITabBarController alloc] init]; 


    if ([PFUser currentUser]) { 
     // Present wall straight-away 
     [self presentWallViewControllerAnimated:NO]; 
    } else { 
     // Go to the welcome screen and have them log in or create an account. 
     [self presentLoginViewController]; 
    } 

    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions]; 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window.rootViewController = self.navigationController; 
    [self.window makeKeyAndVisible]; 

私はそれに切り替えたいデリゲートメソッド:

- (void)presentWallViewControllerAnimated:(BOOL)animated { 
    NSLog(@"Called:presentWallViewControllerAnimated "); 
// self.navigationController = nil; 

    self.tabBarController = [[UITabBarController alloc] init]; 

    PAWWallViewController *wallViewController = [[PAWWallViewController alloc] initWithNibName:nil bundle:nil]; 
    wallViewController.delegate = self; 


    // Set up the first View Controller 
    UIViewController *vc1 = [[UIViewController alloc] init]; 
    vc1.view.backgroundColor = [UIColor orangeColor]; 
    vc1.tabBarItem.title = @"Orange"; 
    vc1.tabBarItem.image = [UIImage imageNamed:@"heart"]; 

    // Set up the second View Controller 
    UIViewController *vc2 = [[UIViewController alloc] init]; 
    vc2.view.backgroundColor = [UIColor purpleColor]; 
    vc2.tabBarItem.title = @"Purple"; 
    vc2.tabBarItem.image = [UIImage imageNamed:@"star"]; 

    // Set up the Tab Bar Controller to have two tabs 

    [self.tabBarController setViewControllers:@[ vc1, vc2]]; 

    self.window.rootViewController = self.tabBarController; 

    [self.window makeKeyAndVisible]; 



// [self.window addSubview:tabBarController.view]; 
// [self.navigationController setViewControllers:@[ tabBarController ] animated:animated]; 
} 

答えて

0

がビュー遷移を扱うことを忘れないでください:

UIViewController *vc = // any vc that's initialized properly  
window.rootViewController = vc; 

[UIView transitionWithView:window 
        duration:0.3 // 0.0 for immediate 
        options:UIViewAnimationOptionTransitionCrossDissolve // several enums to choose from here 
       animations:nil 
       completion:nil]; 

、あなたが最初の時間が経過した後makeKeyAndVisibleを必要としません。

+0

これはうまくいきませんでした。私はまだblackviewでnavbarを見ています – Abdoelrhman

0

あなたは- (void)presentWallViewControllerAnimated:(BOOL)animatedと呼ばれるが、didFinishLaunchingWithOptionsの最後に、あなたが

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.window.rootViewController = self.navigationController; 
[self.window makeKeyAndVisible]; 

と呼ばれるので、タブバーが働くことは決してありません!

+0

次に何をすべきですか? – Abdoelrhman

+0

'didFinishLaunchingWithOptions'の最後にこれらのコードを削除します。そして、if/else 'if([PFUser currentUser])'コードのrootViewControllerを確認してください。 – Proton

+0

以上ですが、ログインまたはサインアップビューを表示するにはナビゲーションコントローラが必要ですか? – Abdoelrhman