progNewbie
progNewbie

Reputation: 4812

Dismiss all Views from NavigationViewController

I have the following setup:

AuthVC || Navigator => TabBarContr => MainVC/SecondVC

                               => SettingsVC

In my AuthVC I check if the user is logged in. If yes I just open my Navigator class which is a NavigationViewController and which has my "TabBarContr" as rootview. There I have two TabBarItems. In the Navigationbar of my TabBarContr I have a 'settings' button which opens my SettingsVC. In there I have a logout button. When pressed, I logout and want to kill everything except my authVC-Controller so that I can reopen my login-VC at that point.

What I am doing: When logout is pressed I link back from my SettingsVC to my TabBarContr. There I call dismissViewController.

I thought this would work because I really get back to my AuthVC. But after logging in again it opens my TabBarContr and there I got some issues loading stuff because some objects are still living from my previous logged-in session.

So what do I need to do to really kill everything except AuthVC?

Upvotes: 1

Views: 90

Answers (4)

SAIF
SAIF

Reputation: 125

Try this

let maiStoryBoard = UIStoryboard(name: "Main", bundle: nil) //Storyboard in which AuthVC lies

let authVC = mainStoryBoard.instantiateViewControllerWithIdentifier("AuthVC") as! AuthVC
 let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
 appDelegate.window?.rootViewController = authVC

Upvotes: 0

Pablo Alegre
Pablo Alegre

Reputation: 37

"... But after logging in again it opens my TabBarContr and there I got some issues loading ..."

If I understood you are removing every view, but your problem is your viewcontrollers are not properly restarted. You may have some retained reference so you are reusing the vc objects and then you have some issue presenting them for the second time. Try reviewing what references are not released when you dismiss/pop.

Upvotes: 1

Viren Malhan
Viren Malhan

Reputation: 115

set AuthVC as your window's rootViewController.

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

instantiate AuthVC from storyboard and assign it to window's rootViewController

appDelegate.window?.rootViewController = AuthVC

Upvotes: 1

Gkolunia
Gkolunia

Reputation: 92

Or you can set root view controller for the window by next code in your settingsVC:

//Did tap logout button
self.view.window?.rootViewController = AuthVC

If it doesn't help you, please send how exactly you show NavigationViewController after AuthVC.

Upvotes: 0

Related Questions