2

I have the following layout of view controllers:

loginViewController -> tabBarViewController -> navigationViewController -> mainTableViewController -> logoutViewController.
                                            \
                                             --> navigationViewController -> secondaryTableViewController                                                 

If the user successfully logs in he goes to the first tab of the tabBarViewController which is itself the first viewController (the mainTableViewController) from a navigationViewController. Consider that this mainTableViewController shows several options, each one leading to its own viewController, being the logoutViewController one of the options.

In the logoutView i have a button to logout (cool uh?) and if logout succeeds I want to go back to the loginViewController.

I tried calling:

 [self.navigationController popToRootViewControllerAnimated:NO];

from the logoutViewController but nothing happens. I searched other similar questions but most of them suggests the use of popToRootViewControllerAnimated. I don't think it's that simple since I have a navigationController pushed from a tabBarController pushed from a viewController. What's the best way of doing this?

I hope it's not too confusing. Thanks.

JSeven
  • 625
  • 1
  • 6
  • 12
  • Perhaps I could store the loginViewController in a property of the tabBarController and use [self popToViewController:tabBarController.loginViewController] ? – JSeven Apr 23 '12 at 16:54

1 Answers1

0

I assume the path is stored in some LiFo way; why don't you just Pop till the count = 1?

NKCSS
  • 2,716
  • 1
  • 22
  • 38
  • You mean calling popViewController and counting the returned array in a loop or something? – JSeven Apr 23 '12 at 14:00
  • I don't have a concrete example, more a general programming reference. if you store your path in a Stack and do: Push loginViewController, Push tabBarViewController, Push navigationviewcontroller. If you Check the Stack's count, it will list 3. So, var ThisWillBeTheLoginController; while(Stack.Count > 0) ThisWillbeTheLoginController = Stack.Pop(); this should leave you with the loginViewController. Not sure how it would translate to ObjectiveC, but this pattern should be programmable in basically any language. Example: http://stackoverflow.com/questions/7567827/last-in-first-out-stack-with-gcd – NKCSS Apr 23 '12 at 14:35