0

I have 3 views with 3 controllers: HomeView -> LoginView -> AccountView In HomeView I added a NavigationBarController. When the user logs in in the LoginView, he is moved to the AccountView. When He clicks on the back button in the NavigationBar, he is sent to the LoginView and this is the problem. After logging if the user clicks on the back button, I want to show him the HomeView and not the LoginView. I tried this code but it takes some time to be executed and I can see the LoginView for some milliseconds.

override func viewWillAppear(animated: Bool) {   
    if let token = userDefaults.valueForKey("token") { //User logged in
        self.performSegueWithIdentifier("homeSegue", sender: self)
    }
}

Is there another way to do it?

solidcell
  • 7,639
  • 4
  • 40
  • 59
User1238
  • 87
  • 8
  • First you need to check your storyboard connected segue because some where you are connected seque with ibaction and you also calling it by suing `performSegueWithIdentifier` – Nitin Gohel Jul 06 '16 at 11:46

2 Answers2

0

If login is success, why don't you just use

self.navigationController?.popToRootViewControllerAnimated(true)
mshrestha
  • 788
  • 5
  • 14
0

at the viewDidApper in the AccountView, you can delete the LoginView from the ViewControllers stack this way

self.navigationController?.viewControllers.removeAtIndex(1)

this way, if user will go back, he/she will see the home page as requested

ddb
  • 2,423
  • 7
  • 28
  • 38