Septiadi Agus
Septiadi Agus

Reputation: 1775

Why UINavigationController keep popping out the top controller

I have UITabBarController, one of the tab points to a UINavigationController. The UINavigationController rootViewController is of class BGProfileView which shows users' profile

At viewDidAppear, I arranged that if users didn't logged in it will push a BGLogin view controller.

[BGLogin alreadyLoggedin:self.navigationController hideBackButton:YES anddoBlock:^{
    [self whatToDoAfterLogin];
}];

Now everything is fine but with one minor issue. If I press the tab again, BGLogin will be poped out of UINavigationController.

I have no idea what makes that BGLogin poped out.

If I select a different tab and then click back to the BGProfile tab, this doesn't happen. It just happens when I click the same active tab. So I am in BGProfile tab, and I click that tab again. Basically it happens when I select the active tab that should simply do nothing. In fact, it does do nothing on others.

I put a breakpoint in viewWillDisappear and this is what I see:

enter image description here

As you see, viewDidAppear is called by the main loop. But why the hell the mainloop call viewDidAppear? Usually there is a code saying things like nav popViewController

Upvotes: 0

Views: 93

Answers (1)

Mihir Mehta
Mihir Mehta

Reputation: 13843

Chances are there . that your tab bar controller is pushing new navigation controller with root view controller. and you interpreting that it's popping out. When same tab is selected you need to tell your tabBarController to not to do anything explicitly.

Example

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    UIViewController *tbSelectedController = self.tabBarController.selectedViewController;

    if ([tbSelectedController isEqual:viewController]) {
        return NO;
    }

    return YES;
}

Upvotes: 3

Related Questions