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

      <tfoot id='Ewu6O'></tfoot>

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

        iOS:“单向"的最佳实践导航控制器?

        iOS: Best practices for a quot;one-wayquot; navigation controller?(iOS:“单向的最佳实践导航控制器?)

      1. <legend id='69W1E'><style id='69W1E'><dir id='69W1E'><q id='69W1E'></q></dir></style></legend>
          <bdo id='69W1E'></bdo><ul id='69W1E'></ul>
        • <tfoot id='69W1E'></tfoot>
            • <small id='69W1E'></small><noframes id='69W1E'>

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

                    <tbody id='69W1E'></tbody>
                  本文介绍了iOS:“单向"的最佳实践导航控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个应用程序,该应用程序本质上是一系列不同的测试(为简单起见,请考虑 SAT 测试或 Mensa 测试).每个测试都在不同的 View+View Controller 中实现.

                  I'm developing an app which is essentially a sequence of many different tests (for simplicity, think about an SAT test or a Mensa test). Each test is implemented in a different View+View Controller.

                  最初我想使用 Storyboards 和 UINavigationControllers 来管理测试的顺序和它们之间的转换,但现在我质疑这种方法的有效性.UINavigationController 是一个堆栈,而我的导航是单向的(一旦你完成了测试,你就不能返回).有没有更好的方法来实现该应用程序?我还能以某种方式利用故事板吗?

                  Initially I wanted to use Storyboards and UINavigationControllers for managing the sequence of the tests and the transitions between them, but now I'm questioning the validity of this approach. A UINavigationController is a stack while my navigation is one-way only (once you've completed a test you can't go back). Is there a better way to implement the app? Can I still leverage Storyboards somehow?

                  推荐答案

                  我会使用自定义容器视图控制器.因此,在您的主要场景中,添加一个容器视图".如果您的目标是 iOS6,那么在编辑情节提要时会有一个特殊的容器视图"对象,您现在可以将其拖到自定义容器视图控制器的场景中:

                  I'd use a custom container view controller. So to your main scene, add a "container view". If your target is iOS6, then when editing your storyboard there is a special "container view" object that you can now drag onto your custom container view controller's scene:

                  如果是 iOS 5,那么 (a) 您必须手动创建第一个子场景;(b) 给它一个唯一的故事板 ID(在我的示例中,InitialChild,并且 (c) 您手动实例化第一个子控制器并以编程方式将其添加为子控制器.因此,假设您有一个 UIView 在您的自定义容器视图控制器的场景中调用 containerView,您可以使用如下方法:

                  If iOS 5, then (a) you have to create the first child scene manually; (b) give it a unique storyboard id (in my example, InitialChild, and (c) you manually instantiate that first child controller and add it as a child programmatically. Thus, assuming you have a UIView called containerView in your custom container view controller's scene, you can have a method like:

                  - (void)addInitialChild
                  {
                      UIViewController *child = [self.storyboard instantiateViewControllerWithIdentifier:@"InitialChild"];
                  
                      [self addChildViewController:child];
                      child.view.frame = self.containerView.bounds;
                      [self.containerView addSubview:child.view];
                      [child didMoveToParentViewController:self];
                  }
                  

                  当你想过渡到下一个场景时,继承你自己的 UIStoryboardSegue:

                  When you want to transition to the next scene, subclass your own UIStoryboardSegue:

                  在 ReplaceSegue.h 中:

                  In ReplaceSegue.h:

                  @interface ReplaceSegue : UIStoryboardSegue
                  
                  @end
                  

                  在 ReplaceSegue.m 中

                  In ReplaceSegue.m

                  @implementation ReplaceSegue
                  
                  - (void)perform
                  {
                      UIViewController *source = self.sourceViewController;
                      UIViewController *destination = self.destinationViewController;
                      UIViewController *container = source.parentViewController;
                  
                      [container addChildViewController:destination];
                      destination.view.frame = source.view.frame;
                      [source willMoveToParentViewController:nil];
                  
                      [container transitionFromViewController:source
                                             toViewController:destination
                                                     duration:0.5
                                                      options:UIViewAnimationOptionTransitionCrossDissolve
                                                   animations:^{
                                                   }
                                                   completion:^(BOOL finished) {
                                                       [source removeFromParentViewController];
                                                       [destination didMoveToParentViewController:container];
                                                   }];
                  }
                  @end
                  

                  然后,当从第一个包含的场景到下一个场景进行转场时,指定一个自定义"转场,并使用这个ReplaceSegue"作为类(只需单击转场将其选中,然后查看属性"检查员").

                  Then, when doing a segue from the first contained scene to the next, specify a "custom" segue, and use this "ReplaceSegue" as the class (just click on the segue to select it and then look at the "Attributes inspector").

                  生成的故事板可能如下所示(注意各个子级之间的{}"标识):

                  The resulting storyboard might look like (note the "{}" designation between the various children):

                  参考资料:

                  • 有关遏制的一般讨论,请参阅 UIViewController 类参考中的 doc/uid/TP40006926-CH3-SW81">实现视图容器控制器.

                  • For general discussion of containment, see Implementing a View Container Controller in the UIViewController Class Reference.

                  有关实现的一些详细信息,请参阅 创建自定义容器视图控制器在 iOS 的视图控制器编程指南中.

                  For some details about the implementation, see Creating Custom Container View Controllers in the View Controller Programming Guide for iOS.

                  这篇关于iOS:“单向"的最佳实践导航控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  UINavigationController inside a UITabBarController inside a UISplitViewController presented modally on iPhone(UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上) - IT屋-程序员软件开发技术分
                  ViewController in UINavigationController orientation change(UINavigationController 中的 ViewController 方向更改)
                  Custom back button in UINavigationController(UINavigationController 中的自定义后退按钮)
                  How to add a navigation controller programmatically in code but not as initial view controller(如何在代码中以编程方式添加导航控制器,但不作为初始视图控制器)
                  The correct way to set a light status bar text color in iOS 7 based on different ViewControllers(iOS 7中基于不同ViewControllers设置灯光状态栏文字颜色的正确方法)
                  View being blocked by UITransitionView after being presented(呈现后被 UITransitionView 阻止的视图)
                      <i id='Uk0dv'><tr id='Uk0dv'><dt id='Uk0dv'><q id='Uk0dv'><span id='Uk0dv'><b id='Uk0dv'><form id='Uk0dv'><ins id='Uk0dv'></ins><ul id='Uk0dv'></ul><sub id='Uk0dv'></sub></form><legend id='Uk0dv'></legend><bdo id='Uk0dv'><pre id='Uk0dv'><center id='Uk0dv'></center></pre></bdo></b><th id='Uk0dv'></th></span></q></dt></tr></i><div id='Uk0dv'><tfoot id='Uk0dv'></tfoot><dl id='Uk0dv'><fieldset id='Uk0dv'></fieldset></dl></div>
                        <tbody id='Uk0dv'></tbody>

                          <bdo id='Uk0dv'></bdo><ul id='Uk0dv'></ul>

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

                        • <tfoot id='Uk0dv'></tfoot>
                          1. <legend id='Uk0dv'><style id='Uk0dv'><dir id='Uk0dv'><q id='Uk0dv'></q></dir></style></legend>