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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...