0

I have one ViewController with button Checkout, On tap checkout button CartViewController should open if user is logged in but if the user is not logged in the LoginViewController should open and after login CartViewController should open, This is working fine but my problem is when I tap on buck button of navigation bar in CartViewController it is showing LoginViewController if it is coming from LoginViewController. I want it to go back to ViewController every time

Varun Naharia
  • 5,318
  • 10
  • 50
  • 84

2 Answers2

0

You can manipulate the viewControllers property of UINavigationController object to remove a particular object from stack. So when you are taking the route of ViewController -> LoginViewController-> CartViewController, then you should remove the LoginViewController object from the stack. That way when you pop from CartViewController you will be back to ViewController.
Check This Question for how to manipulate navigation controller stack

Community
  • 1
  • 1
Gandalf
  • 2,399
  • 2
  • 15
  • 19
-1

Write below code (for removing the to rootViewController) on Navigation Back bar button Item Action:
Code:

[self.navigationController popToRootViewControllerAnimated:YES];
Ashok Londhe
  • 1,491
  • 11
  • 29
  • You are assuming it as if the ViewController is the initial point of application. What if the ViewController is not the root object in stack? – Gandalf Jul 07 '15 at 07:22
  • @Gandalf you are right. but i think for this question view controller it the RootViewController... – Ashok Londhe Jul 07 '15 at 07:26
  • Yes i understand this will work perfectly if that is the case. But it may or may not be. I believe when things are not clear then solution should be more generic. – Gandalf Jul 07 '15 at 07:30
  • @Gandalf Yes. you are absolutely correct but in this question he has mention that. (if he has an view controller and doing navigation start navigation from it then it should be the Root View Controller) so as per my opinion for this question this it the perfect answer. – Ashok Londhe Jul 07 '15 at 07:37