0

I am using the Storyboard, then in my AppDelegate has no navigation controller programming on hand (all normal so far).

Now i need to fire the "applicationDidEnterBackground" I would like my app point to the navigation controller to the first screen (ie) popToView or popToRoot.

I tried to use some means found as:

EDITED: - Insert the applicationDidEnterBackgoround Method

//*-- BEGIN
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    _mainMenuDelegate = [[UIStoryboard storyboardWithName: stb_name bundle: nil] instantiateViewControllerWithIdentifier: @ "idMainMenu"];
    [[_window.rootViewController navigationController] popToViewController: _mainMenuDelegate animated: NO];

OR

     NSArray * = viewContrlls _window.subviews;
     for (int i = 0; i <[viewContrlls count], i + +)
     {
        id obj = [viewContrlls objectAtIndex: i];
        if ([obj isKindOfClass: [MainMenu class]])
        {
            [[_window.rootViewController navigationController] popToViewController: obj animated: YES];
            return;
        }
     }
 } //*-- END

But the first does not fire and, the second is just 1 result row and it is not the MainMenu, so do not jump to the ViewController.

My question is: How to do it, knowing that I am using Storyboard?

Thank you

Daniel Arantes Loverde
  • 2,317
  • 2
  • 28
  • 41

1 Answers1

0

Try that:

NSArray* viewControllers = [[_window.rootViewController navigationController] viewControllers];

for (int i = 0; i < [viewControllers count]; i++)
{
    id obj = [viewControllers objectAtIndex: i];

    if ([obj isKindOfClass: [MainMenu class]])
    {
        [[_window.rootViewController navigationController] popToViewController: obj
                                                                      animated: YES];

        return;
    }
}

Hope it helps you.

stosha
  • 2,108
  • 2
  • 27
  • 29