Вы можете создать такую функцию:
- (void) dropWithViewController:(UIViewController*)vc {
if( [vc modalViewController] ){
[self dropWithViewController:[vc modalViewController]];
[vc dismissModalViewControllerAnimated:NO];
} else if( [vc isKindOfClass:[UINavigationController class]] ){
[self dropWithViewController:[(UINavigationController*) vc topViewController]];
UINavigationController *nc = (UINavigationController*)vc;
for( int i=0;i<[[nc viewControllers] count]-1;i++ ){
[nc popViewControllerAnimated:NO];
}
} else if( [vc isKindOfClass:[UITabBarController class]]){
[self dropWithViewController:[(UITabBarController*) vc selectedViewController]];
} else {
//you're at the last view, on return it will start going back
return;
}
}
И затем вызывать ее так, когда приложение входит в фоновый режим (см. UIApplicationDelegate, - (void) applicationDidEnterBackground: (UIApplication *) application):
- (void )dropAllViewControllers{
UIViewController *firstViewController = [[[UIApplication sharedApplication]keyWindow] rootViewController];
[self dropWithViewController:firstViewController];
}