<legend id='r9RPP'><style id='r9RPP'><dir id='r9RPP'><q id='r9RPP'></q></dir></style></legend>
    • <bdo id='r9RPP'></bdo><ul id='r9RPP'></ul>
    <tfoot id='r9RPP'></tfoot>

      <small id='r9RPP'></small><noframes id='r9RPP'>

        <i id='r9RPP'><tr id='r9RPP'><dt id='r9RPP'><q id='r9RPP'><span id='r9RPP'><b id='r9RPP'><form id='r9RPP'><ins id='r9RPP'></ins><ul id='r9RPP'></ul><sub id='r9RPP'></sub></form><legend id='r9RPP'></legend><bdo id='r9RPP'><pre id='r9RPP'><center id='r9RPP'></center></pre></bdo></b><th id='r9RPP'></th></span></q></dt></tr></i><div id='r9RPP'><tfoot id='r9RPP'></tfoot><dl id='r9RPP'><fieldset id='r9RPP'></fieldset></dl></div>

      1. 如何从推送的控制器中获取 RootViewController?

        How do I get the RootViewController from a pushed controller?(如何从推送的控制器中获取 RootViewController?)
      2. <tfoot id='5ettt'></tfoot>

        <legend id='5ettt'><style id='5ettt'><dir id='5ettt'><q id='5ettt'></q></dir></style></legend>

            <tbody id='5ettt'></tbody>

            <bdo id='5ettt'></bdo><ul id='5ettt'></ul>
              • <small id='5ettt'></small><noframes id='5ettt'>

                <i id='5ettt'><tr id='5ettt'><dt id='5ettt'><q id='5ettt'><span id='5ettt'><b id='5ettt'><form id='5ettt'><ins id='5ettt'></ins><ul id='5ettt'></ul><sub id='5ettt'></sub></form><legend id='5ettt'></legend><bdo id='5ettt'><pre id='5ettt'><center id='5ettt'></center></pre></bdo></b><th id='5ettt'></th></span></q></dt></tr></i><div id='5ettt'><tfoot id='5ettt'></tfoot><dl id='5ettt'><fieldset id='5ettt'></fieldset></dl></div>
                • 本文介绍了如何从推送的控制器中获取 RootViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  所以,我从 RootViewController 推送一个视图控制器,例如:

                  <上一页>[self.navigationController pushViewController:anotherViewController Animation:YES] ;

                  但是,从 anotherViewController 现在,我想再次访问 RootViewController.

                  我在努力

                  <上一页>//(现在在另一个视图控制器中)///RootViewController *root = (RootViewController*)self.parentViewController ;//不.//呃RootViewController *root = (RootViewController*)[self.navigationController.viewControllers objectAtIndex:0] ;//是的!!有用

                  我不确定为什么这样做有效,我不确定这是否是最好的方法.有人可以评论从您推送到该 RootViewController 的 navigationController 的控制器中获取 RootViewController 的更好方法以及我所做的方式是否可靠?

                  解决方案

                  使用viewControllers 属性.示例代码:

                  //在另一个 ViewController 中NSArray *viewControllers = self.navigationController.viewControllers;UIViewController *rootViewController = [viewControllers objectAtIndex:viewControllers.count - 2];

                  这是获取后退"视图控制器的标准方法.objectAtIndex:0 起作用的原因是因为您尝试访问的视图控制器也是根视图,如果您在导航中更深入,则后视图与根视图不同.

                  So, I push a view controller from RootViewController like:

                  [self.navigationController pushViewController:anotherViewController animated:YES] ;
                  

                  BUT, FROM anotherViewController now, I want to access the RootViewController again.

                  I'm trying

                  // (inside anotherViewController now)
                  ///RootViewController *root = (RootViewController*)self.parentViewController ; // No.
                  // err
                  RootViewController *root = (RootViewController*)[self.navigationController.viewControllers objectAtIndex:0] ; // YES!! it works
                  
                  

                  I'm not sure WHY this works and I'm not sure if its the best way to do it. Can somebody comment on a better way to get the RootViewController from a controller you've pushed into that RootViewController's navigationController and whether or not the way I've done it is reliable or not?

                  解决方案

                  Use the viewControllers property of the UINavigationController. Example code:

                  // Inside another ViewController
                  NSArray *viewControllers = self.navigationController.viewControllers;
                  UIViewController *rootViewController = [viewControllers objectAtIndex:viewControllers.count - 2];
                  

                  This is the standard way of getting the "back" view controller. The reason objectAtIndex:0 works is because the view controller you're trying to access is also the root one, if you were deeper in the navigation, the back view would not be the same as the root view.

                  这篇关于如何从推送的控制器中获取 RootViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)
                  CABasicAnimation rotate returns to original position(CABasicAnimation 旋转返回原始位置)
                  UITabBarController Rotation Issues in ios 6(ios 6 中的 UITabBarController 旋转问题)
                  iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))
                  UIImageView Gestures (Zoom, Rotate) Question(UIImageView 手势(缩放、旋转)问题)
                  Responsive website on iPhone - unwanted white space on rotate from landscape to portrait(iPhone上的响应式网站-从横向旋转到纵向时不需要的空白)

                  <i id='c67cc'><tr id='c67cc'><dt id='c67cc'><q id='c67cc'><span id='c67cc'><b id='c67cc'><form id='c67cc'><ins id='c67cc'></ins><ul id='c67cc'></ul><sub id='c67cc'></sub></form><legend id='c67cc'></legend><bdo id='c67cc'><pre id='c67cc'><center id='c67cc'></center></pre></bdo></b><th id='c67cc'></th></span></q></dt></tr></i><div id='c67cc'><tfoot id='c67cc'></tfoot><dl id='c67cc'><fieldset id='c67cc'></fieldset></dl></div>
                    • <small id='c67cc'></small><noframes id='c67cc'>

                        <tbody id='c67cc'></tbody>
                        <bdo id='c67cc'></bdo><ul id='c67cc'></ul>

                          <tfoot id='c67cc'></tfoot>

                          <legend id='c67cc'><style id='c67cc'><dir id='c67cc'><q id='c67cc'></q></dir></style></legend>