2
votes

I have application with navigationController and some root viewController in it's stack. I need a way to reset application's state to default, i.e. when there is only navigationController and it's root viewController from any moment in my application. For example, I make some background data request to backend and get response, which says that I have to logout user immediately. In that moment, let's assume, user has opened a lot of other viewControllers in navigationController stack and maybe some presented viewControllers with their own navigationControllers. So what I need is a way to pull user back from wherever he is to the root viewController of application.

I'm aware of the fact that this is a bad user experience, but it's definitely better than crashing app, and anyway this should be a rare situation.

I don't think that creating a chain reaction between all viewControllers that will one-by-one dismiss them until it reaches my root viewController is a good idea for me. That's too much of identical code in every VC, and I don't want to create subclass of UIViewController and subclass all of my VCs from it to have this done.

Any suggestions?

1
I ended up using a chain reaction between all viewControllers and having all of my VCs subclassed from custom sublclass of UIViewController with default logic implemented there. I guess there was no way to avoid that. - DemoniacDeath

1 Answers

0
votes

You can use [self.navigationController popToRootViewControllerAnimated:YES]; to go to your main rootview controller from any view of your app.