简体   繁体   English

从模式视图中推送视图,然后从popToRootView中推送

[英]Push view from modal view and then popToRootView

Here are my ViewControllers as fallows(objects): 这是我的ViewControllers(休假对象):

  • FirstViewController - view with tab bar + navigation bar, also part of the ta bar; FirstViewController带有标签栏和导航栏的视图,也是ta栏的一部分;
  • SecondViewController - view only with navigation controller SecondViewController仅使用导航控制器查看
  • ThirdViewController - view only with navigation controller ThirdViewController仅使用导航控制器查看

And what I am trying to do(logical steps): 而我正在尝试做的(逻辑步骤):

  1. present SecondViewController from FirstViewController (modal) SecondViewControllerFirstViewController (模态)

  2. push ThirdViewController from SecondViewController (push) ThirdViewControllerSecondViewController (推)

  3. popToRootViewControllerAnimated - to pop from ThirdViewController to FirstViewController (pop) popToRootViewControllerAnimatedThirdViewController弹出到FirstViewController (pop)

And here is the code that I am using by steps: 这是我按步骤使用的代码:

  1. in FirstViewController class FirstViewController类中

     SecondViewController * secondViewController = [[UIStoryboard MainStoryboard] instantiateViewControllerWithIdentifier:NSStringFromClass([SecondViewController class])]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: secondViewController]; [self.navigationController presentViewController: navigationController animated:YES completion:nil]; 
  2. in SecondViewController class: SecondViewController类中:

     ThirdViewController * thirdViewController = [[UIStoryboard MainStoryboard] instantiateViewControllerWithIdentifier:NSStringFromClass([ThirdViewController class])]; [self.navigationController pushViewController: thirdViewController animated:YES]; 
  3. and in ThirdViewController class I do: ThirdViewController类中,我这样做:

     [self.navigationController popToRootViewControllerAnimated:YES]; 

My issues is on point 3, when I do the pop to root view controller instead of going from ThirdViewController to FirstViewController it only goes to SecondViewController . 我的问题是在第3点上,当我执行弹出到根视图控制器而不是从ThirdViewControllerFirstViewController它仅转到SecondViewController

In step 1 you created new UINavigationController instance and you set secondViewController as the rootViewController for it. 在步骤1中,您创建了新的UINavigationController实例,并将secondViewController设置为其的rootViewController。 So now in step 2 when you are pushing the thirdViewController it will get added to the navigation stack of secondViewController. 因此,现在在第2步中,当您推动ThirdViewController时,它将被添加到secondViewController的导航堆栈中。 Finally in step 3 when you are calling "popToRootViewControllerAnimated" it will pop to secondViewController, since secondViewController is the rootViewController of the navigation. 最后,在第3步中,当您调用“ popToRootViewControllerAnimated”时,它将弹出至secondViewController,因为secondViewController是导航的rootViewController。

To go to FirstViewController call "dismissViewControllerAnimated" on self.navigationController. 要转到FirstViewController,请在self.navigationController上调用“ dismissViewControllerAnimated”。

Please refer the below code. 请参考下面的代码。

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

Forget about the frist step. 忘记第一个步骤。 Even though you are presenting a view controller modally, you are making it a root view controller till you dismiss it. 即使您以模态方式显示视图控制器,也要使其成为根视图控制器,直到您将其关闭为止。

  1. You are pushing it from second VC nav controller. 您正在从第二个VC nav控制器推送它。

  2. If you pop it, you will go back to second VC, as the third VC is pushed on second nav controller. 如果弹出它,您将返回到第二个VC,因为第三个VC被推到第二个导航控制器上。

If you want to go to your first View controller,present the first VC again in the third VC by 如果要转到第一个View控制器,请通过以下方式在第三个VC中再次显示第一个VC:

  [self presentViewController:firstVC animated:YES completion:nil];

or you can dismiss 或者你可以解雇

  [self.navigationController dismissViewController animated:YES completion:nil];

Please note that you cannot have multiple navigation controllers in the reference. 请注意,参考中不能有多个导航控制器。 You can have only one at any time. 您随时只能拥有一个。

Even though you present the second VC by from first VC nav controller 即使您通过第一个VC导航控制器显示第二个VC

  [self.navigationController  presentViewController:secondVC animated:YES completion:nil];

you are presenting the second VC navigation controller here, so in the first VC navigation stack another nav controller will be added. 您将在此处显示第二个VC导航控制器,因此,在第一个VC导航堆栈中,将添加另一个导航控制器。 At this point, the second VC navigation controller will be in reference when you call self.navigationController in the secondVC 此时,当您在第二个VC中调用self.navigationController时,将引用第二个VC导航控制器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从故事板中的模态视图推送视图控制器 - Push View Controllers from Modal View in Storyboard 将视图从另一个选项卡的模式推送到导航 - Push view to navigation from modal of another tab 从Modal View内部推送到iOS NavigationController - Push to iOS NavigationController from inside Modal View 将视图控制器推入模态视图控制器视图 - Push view controller into modal view controller view 模式下的弹出/推入视图 - Pop/push view under modal 从模式视图或推送视图调用父方法到presentingViewController - Calling parent method from a modal or push view to presentingViewController 从推送通知中获取对象并在模式视图控制器中显示 - Get object from push notification and show in modal view controller 如何从呈现为半模式的视图控制器中将视图控制器推为全屏 - How to push a view controller as a full screen from the view controller presented as a half-modal 使用Storyboard Segues将视图控制器从模态推送到模态父级使用的导航控制器 - Push view controller from modal into navigation controller used by parent of the modal using Storyboard segues 从Modal View Controller推入/弹出到另一个View Controller(包括图片) - Push/pop to another view controller from a Modal View Controller (includes picture)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM