Wednesday, 31 July 2019

Removing viewcontrollers from navigation stack



When session expired move to login page : Removing viewcontrollers from navigation stack

//If session expaired move to login page
if message == "Session Expired" {
    DispatchQueue.main.async {
        //Check navigation stacks
        let navigationArray = self.navigationController?.viewControllers //To get all UIViewController stack as Array
        print(navigationArray!)//Prints navigation stacks

        //Remove all navigations
        self.navigationController!.viewControllers.removeAll()
        //Remoce particular VC navigation
        //self.navigationController?.viewControllers.remove(at: "insert here a number")

        //Check navigation stacks
        let navigationArray2 = self.navigationController?.viewControllers //To get all UIViewController stack as Array
        print(navigationArray2 as Any)//Prints nill

        //Check whether the user logined or not
        UserDefaults.standard.set(false, forKey: "isUserLoggedIn")
        //Clear user defaults
        SharedClass.sharedInstance.clearDataFromUserDefaults()

        let lvc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LVC") as! LoginViewController
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window?.rootViewController = lvc                                
    }
}



No comments:

Post a Comment

Difference between == and ===

Difference between == and === https://stackoverflow.com/questions/24002819/difference-between-and == operator checks if their ...