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都实现了展开动作,您应该是好的.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...