2
votes

When I create four navigation controllers and add them to a UITabBar like so:

// Create the root view controllers for the tab bar
firstViewController = [[FirstViewController alloc] init];
secondViewController = [[SecondViewController alloc] init];
thirdViewController = [[ThirdViewController alloc] init];
fourthViewController = [[FourthViewController alloc] init];

// Configure the tab bar
UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.viewControllers = @[
[[[UINavigationController alloc] initWithRootViewController:firstViewController] autorelease],
[[[UINavigationController alloc] initWithRootViewController:secondViewController] autorelease],
[[[UINavigationController alloc] initWithRootViewController:thirdViewController] autorelease],
[[[UINavigationController alloc] initWithRootViewController:fourthViewController] autorelease]
];
tabBarController.selectedIndex = 1;

self.window.rootViewController = tabBarController;

I'm having an issue where which ever UINavigationController is first visible on launch (in this case index 1) has a strange 'pop' animation. The title and such in the nav bar animate properly, but the content of the navigation controller changes without animation.

Selecting a different tab, and then returning to the original tab corrects the problem.

Also if I set self.window.rootViewController to [[[UINavigationController alloc] initWithRootViewController:secondViewController] autorelease] so as to leave the tab bar out of the equation, the navigation controller works just fine.

Any thoughts?

3

3 Answers

1
votes

I had the same problem and the only solution I found is this little hack:

Put this in your "(void)viewWillAppear" method on the first UITabBarController view controller.

     UITabBarController * controller = self.tabBarController;
     //Create this BOOL variable on your class and set it to YES on viewDidLoad
     if(firstTimeViewLoaded) {    
        // Simulate a click on other tab item then switch back instantly.
        [controller setSelectedViewController:controller.viewControllers[1]];
        [controller setSelectedViewController:controller.viewControllers[0]];
     }
     firstTimeViewLoaded = NO;
1
votes

I had the same problem and found the solution, so for those who stumbled upon this page while googling:

From Pop animation is not working in first UINavigationController of UITabbarController:

You probably forgot to write [super viewDidAppear:animated]; inside the -(void)viewDidAppear:(BOOL)animated method:

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}

This should fix it.

0
votes
 // Create the root view controllers for the tab bar
firstViewController = [[FirstViewController alloc] init];
secondViewController = [[SecondViewController alloc] init];
thirdViewController = [[ThirdViewController alloc] init];
fourthViewController = [[FourthViewController alloc] init];

   UINavigationController *myNavigationController;
    UITabBarController *myTabBarController = [[UITabBarController alloc] init];

    NSMutableArray *myTabs = [[NSMutableArray alloc] init];

    myNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
    [myTabs addObject:myNavigationController];
//Release
[myNavigationController release];
//Second view
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
    [myTabs addObject:myNavigationController];
[myNavigationController release];
//And so on with the third and fourth view controller
//...

[tabBarController setViewControllers:myTabs];
//Add the tab bar controller view to the main view
[self.window addSubview:tabBarController.view];