Reputation:
i have an app with 5 views, mostly consisting of drill downs.
lets say i drill down to the 4th view controller. is there a way to present the second view controller exactly as it is without recreating it and modally present that view?
the drill downs do a sort of round about and i dont want to force the user to reselect their selection on the first view to bring them into the second view
so its like this (tvc = tableviewcontroller)
tvc1 > tvc2 > tvc3 > tvc4 > tvc2 > tvc5
^ ^
these two views are the same view in memory
Upvotes: 0
Views: 870
Reputation: 919
You can possibly iterate over the visible viewControllers, and use the is
casting operator to check if it is that type of class. Then find the view controller and pop to it.
Objective-C
for (id viewController in self.navigationController.viewControllers) {
if ([viewController isKindOfClass:[ViewControllerClass class]]) {
[self.navigationController popToViewController:viewController animated:TRUE];
}
}
Swift 2.0
for viewController in self.navigationController!.viewControllers {
if viewController is ViewControllerClass {
self.navigationController?.popToViewController(viewController, animated: true)
}
}
Upvotes: 1
Reputation: 385500
You cannot present tvc2 again while it is already in the "stack" of presented view controllers.
If you push your view controllers onto a navigation controller's stack, then you can change the order of the view controllers in that stack by assigning to its viewControllers
property or by sending it setViewControllers:animated:
. You can hide its navigation bar if you don't want users to see it. I don't think it's safe to put the same view controller into the stack in two places at the same time.
Upvotes: 2
Reputation: 2438
UINavigationController
has an array called viewControllers
. This will give you the list of UIViewControllers
that exist in that navigation stack.
You can try something like:
UIViewController *yourTableViewController = [self.navigationController.viewControllers objectAtIndex:(theIndexOfYourTableViewController)];
Hope this helps.
Upvotes: 0