Push to root View controller in UIStoryboard

2019-04-17 13:33发布

问题:

I have hierarchy of ViewControllers in my storyboard structure. It is A-B-C-D. A is embed with NavigationController and the flow goes on till D viewController. All fours view attached through segues. Now I am on D viewController, I defined some action to the button of D that It should take me directly to A viewController that is rootViewController or B viewController. Then how can I achieve this. I tried everything but didn't succeed.

I want something like it should not disturb A-B-C-D flow and it should take me to A viewController from D.

回答1:

Right click on your D viewcontroller and drag i to your A viewcontroller.

Then click on the object which appears on the line you just created.

Write something like DtoA in the storyboard segue identifier in the attributes inspector.

Now in D view controller, just do:

[self performSegueWithIdentifier:@"DtoA" sender:self];

And if you instead wish to pop to a previous viewcontroller the old fashioned way, like from D to B:

UINavigationController* navController = self.navigationController;
UIViewController* Bviewcontroller = [navController.viewControllers objectAtIndex:1];
[navController popToViewController:controller animated:YES];

I hope this helps!