ios – (Swift)当多个视图控制器导致相同视图时展开segue?

前端之家收集整理的这篇文章主要介绍了ios – (Swift)当多个视图控制器导致相同视图时展开segue?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试编写一个刽子手游戏,并且在解开细分时遇到了麻烦.我有多个视图控制器,最终导致相同的视图,用户在其中播放实际的刽子手.
但是,根据呈现控制器,我希望游戏处于不同的“模式”(即:多人游戏,单人游戏等).我正在尝试添加一个再次播放按钮,该按钮可以展开前一个视图控制器,但是当用户可以使用多个路径进入此视图时,我不确定如何展开.

换句话说,我的应用程序有点:

A – > B – > C或

A – > D – > C其中C可以(理想地)展开到D或B.

我想知道实现这个的最佳方法是什么?我应该将所有视图控制器嵌入导航控制器吗?或者有没有办法根据某种条件呈现某个视图控制器?感谢您的任何帮助!

解决方法

展开segue进程通常会自动确定先前的UIViewController实例. Apple的 Tech Note中描述了确切的过程,但总结如下:

Starting from the view controller that initiated the unwind segue the
search order is as follows:

  1. The next view controller in the responder chain is sent a
    viewControllerForUnwindSegueAction:fromViewController:withSender:
    message. For a view controller presented modally,this will be the
    view controller that called
    presentViewController:animated:completion:. Otherwise,the
    parentViewController.

    The default implementation searches the
    receiver’s childViewControllers array for a view controller that wants
    to handle the unwind action. If none of the receiver’s child view
    controllers want to handle the unwind action,the receiver checks
    whether it wants to handle the unwind action and returns self if it
    does. In both cases,the
    canPerformUnwindSegueAction:fromViewController:withSender: method is
    used to determine if a given view controller wants to handle the
    unwind action.

  2. If no view controller is returned from
    viewControllerForUnwindSegueAction:fromViewController:withSender: in
    step one,the search repeats from the next view controller in the
    responder chain.

因此,精确的过程将取决于您如何呈现视图控制器C – 例如,通过UINavigationController上的模态演示segue或push segue,但只要B和D都实现了展开动作,您应该是好的.

猜你在找的iOS相关文章