Push to root View controller in UIStoryboard

依然范特西╮ 提交于 2019-12-06 14:58:47

问题


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!



来源:https://stackoverflow.com/questions/15024559/push-to-root-view-controller-in-uistoryboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!