1
votes

I am navigating to Tab bar controller with 6 tabs from a RootViewController... I have created back button method in left navbar item which pops back all tab views to RootViewController... Problem arises when i try to pop the 5th or 5th tabview.. the back button doesnt work at all in MoreViewController, 5th tab and 6th tab...

Here's what works: 1)Pops back to RootView from 1 to 4 tabs

2)Pops back to RootView from More View (only first time it works)

3)Pops back to MoreView from 5th/6th View (only first time it works)

Here's what doesnt work: 1)Doesnt pop back to RootView from MoreView

What am i doing wrong?

- (void)viewDidLoad
{
...
   self.tabBarController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemDone target:self action:@selector(goBack)];
...
}

Code for goBack method written in each tab

-(void)goBack{

    [self.navigationController popToRootViewControllerAnimated:NO];
}
2
Its a very strange that 1 to 4 tabs are working but 5 and 6 tab are not working... Did you try [self.navigationController popToRootViewControllerAnimated:YES]; may be it worksSudha Tiwari
i have tried with popToRootViewControllerAnimated:YES .. it only adds extra animations... but the issue still remainsShaunak
I post a code please try that and let me know that it works or notSudha Tiwari

2 Answers

0
votes

Try this.. May be it will help you

NSArray *viewContrlls=[[self navigationController] viewControllers];
    for( int i=0;i<[ viewContrlls count];i++)
    {
        id obj=[viewContrlls objectAtIndex:i];
        if([obj isKindOfClass:[rootController class]])
        {
            [[self navigationController] popToViewController:obj animated:YES];

            return;
        }
    } 
0
votes

I figured out what was the problem and so i am going to answer my own question... I was writing popToRootViewController in each tab.. and so when i enter 5th tab and press back, it would come back to more view tab and forgets about the root view.. So i deleted popToRootViewController from each tab and wrote the code for popping the views at the time of Tab bar declaration in the Root View page... eg. Tab bar declaration, then setting tab bar nav button for going back which calls some method... and in that method i write popToRootViewController...