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
Asked
Active
Viewed 458 times
0

Varun Naharia
- 5,318
- 10
- 50
- 84
-
i have posted the answer please try it. – Ashok Londhe Jul 07 '15 at 07:18
-
I wonder why someone has down-voted each and every post. – Gandalf Jul 07 '15 at 08:21
-
may be they don't know there -1 for them also for each downvote – Varun Naharia Jul 07 '15 at 11:06
-
@VarunNaharia - Any specific reason for Removing the answer from "Accepted" state, when you are not accepting any alternate answer? – Gandalf Nov 10 '15 at 13:15
-
I am removing all down vote question and answer – Varun Naharia Nov 11 '15 at 10:19
2 Answers
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
-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