popViewController does not remove UINavigationBar items

1.1k views Asked by At

I have a strange problem. I found some tipps here and in the internet but I nothing solved my problem. So here is what happens:

I have a TabBar Navigation with 9 items. All of them are UINavigationItems. On one of them I replace the default viewController with another one under certain conditions.

To do that, I use popViewController and pushViewController. This works perfectly but I have the problem, that the UINavigationBar is not in sync with that. That has the effect that I see the correct view but the when I click on the "back" button it shift's to an empty navbar item and from there I come back to the rootViewController ("more" for example).

Here is my code:


- (void)viewWillAppear:(BOOL)animated { 
  if ([[myAppDelegate bcUser] userLoggedIn]) {
    // user is logged in
    MyDataLoggedInViewController *loggedInViewController = [[[MyDataLoggedInViewController alloc] initWithNibName:@"MyDataLoggedInView" bundle:nil] autorelease];
    UINavigationController *navController = self.navigationController;
    [[self retain] autorelease];

    [navController popViewControllerAnimated:YES];
    [navController pushViewController:loggedInViewController animated:YES];
  } 
}

I hope someone can help. I tried everything I found and nothing helped. :-/

Thanks and best wishes, Thomas

1

There are 1 answers

3
Brirony On

Try setting:

[navController popViewControllerAnimated:NO];
[navController pushViewController:loggedInViewController animated:NO];

because you're most likely waiting for animations to complete.