Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ios: How can I make my app go back to root view when App goes Inactive

I want my app to go back to the login screen (Which is the root view in the navigation Controller) when it goes inactive.

I'm in applicationWillResignActive and appdelegate.m does not recognize self.navigationController

I tried to make an outlet or the navigation contller in appdelegate.h using ctrl drag in storyboard but it wouldn't let me.

So does anyone know how to get it to switch to a specific view when it goes inactive?

like image 805
user1515993 Avatar asked Dec 14 '25 05:12

user1515993


1 Answers

You could just display the original uiviewcontroller when your app comes back by doing that code in the method applicationWillEnterForeground or applicationDidBecomeActive

quick code

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    [navigationController popToRootViewControllerAnimated:YES];
}

I am sure not the only or best way to do it but it technically works

like image 163
DirectX Avatar answered Dec 16 '25 16:12

DirectX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!