How can I manage the back button view hierarchy?
Here is the problem
1) Rootview Controller - MYAssetVC-> Embedded in NavigationController by clicking a button on another Addfilevc.
2) Addfilevc Has dropdownTextfield It will push to another vc if the selected tableview row is displayed in the textbox.
3) if I select a different value from the dropdown textbox it will click on vc again wherever I select.
The navigation button on the navigation bar will navigate to my entire view hierarchy that I want to process. if i go to one view it only has to go back once to in a recent visit how to do it.
As I am new to iOS. give any suggestion.
Navigation from 1-> 2-> 3
navigation backbtn 3-> 2-> 1
if i move like this 1-> 2-> 3-> flip 3-> 2 again 2-> 3 back 3-> 2 again 2-> 3
IF I navigate now using back, it displays my entire route, it should navigate like 1-> 2-> 3> and 3-> 2-> 1 if I do 2 and 3 any number of times.
1,2,3 - view controllers.
source to share
Create an IBAction for the back button and use popViewController.
[self.navigationController popViewControllerAnimated:YES];
This will get you back one page. You must write this on all pages that have a Back button and you want to go back one page.
If you want to go back directly to rootViewController try this:
[self.navigationController popToRootViewControllerAnimated:YES];
And if you want to pop into any particular view controller on the stack, you run a for loop to find the viewController you want to navigate to, then just popToViewController, like this:
for (UIViewController *viewController in self.navigationController.viewControllers) {
if ([viewController isKindOfClass:[Addfilevc class]]) {
[self.navigationController popToViewController:viewController animated:YES];
}
}
Hope this helps clean up your concept.
EDIT
In quick:
-
[self.navigationController popViewControllerAnimated:YES];
will becomeself.navigationController?.popViewControllerAnimated(true)
-
[self.navigationController popToRootViewControllerAnimated:YES];
will becomenavigationController?.popToRootViewControllerAnimated(true)
-
And the for loop would be like this:
You can use this if using storyboard
let switchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("view2") as ComposeViewController
self.navigationController?.pushViewController(switchViewController, animated: true)
And the for-in loop
if let viewControllers = self.navigationController?.viewControllers {
for viewController in viewControllers {
self.navigationController!.popToViewController(viewController, animated: true);
}
}
Thank.
source to share