pete
pete

Reputation: 3050

applicationDidBecomeActive to return to home page

Using storyboard and a UINavigationController my app has many UIViewControllers. The initial UIViewController is named viewController and is a kind of home page.

If the user leaves the app and returns, I always want the user always to return to the home page (UIViewController) not the last view before leaving. In my appDelegate, how do I call/display my home page (UIViewController) with the applicationDidBecomeActive: ??

Upvotes: 2

Views: 1327

Answers (4)

Anil Varghese
Anil Varghese

Reputation: 42977

Your applicationDidBecomeActive: can be called for several reasons such as comes to the active state after temporary interruptions (such as an incoming phone call or SMS message) not only for the transition from background to the foreground. I think in your it is better to put the code suggested by others inside applicationWillEnterForeground:

- (void)applicationWillEnterForeground:(UIApplication *)application
 {
   UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
   [navigationController popToRootViewControllerAnimated:NO];
 }

Upvotes: 1

shivam
shivam

Reputation: 1140

Check it.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
ViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:@"viewController"];
self.window.rootViewController = lvc;

Put this code in applicationDidBecomeActive method.

Upvotes: 1

Oliver Atkinson
Oliver Atkinson

Reputation: 8029

If your root view controller for the app is a navigation controller then you can do as Marcin Kuptel states, here is a solution for your context.

 - (void)applicationDidBecomeActive:(UIApplication *)application;
 {
   UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
   [navController popToRootViewControllerAnimated:NO];
 }

Upvotes: 6

Marcin Kuptel
Marcin Kuptel

Reputation: 2664

You can use this:

[navigationController popToRootViewControllerAnimated: NO];

Upvotes: 2

Related Questions