来自弹出ViewController Swift的Segue

时间:2018-09-15 12:53:03

标签: ios swift uiviewcontroller popup segue

我有7个屏幕(VC)的应用程序,它们嵌入在导航控制器中。

我有一个单独的未嵌入的VC。此VC的行为类似于自定义弹出窗口class PopupView: UIViewController {},并通过使用自定义segue(在情节提要板上设置为自定义segue)在应用程序中的每个屏幕上按下按钮来调用它:

open class MIBlurPopupSegue: UIStoryboardSegue {

open override func perform() {
    MIBlurPopup.show(destination, on: source)
} }

在此弹出窗口中,有一个按钮应该打开导航堆栈中嵌入的另一个VC(VC始终相同)。

我要实现的目标是,通过按Popup VC中的按钮,实际上打开导航堆栈中的VC,然后返回到调用Popup的屏幕。

因此,用户旅程将如下所示-打开VC1(2,3,5,6,7)->调用弹出式VC->按下按钮->打开VC4->按下导航后退按钮->返回到VC1。 / p>

我现在所拥有的:

  • 在情节提要中将所有6个屏幕都连接到VC4,并带有segues ID

  • 尝试过performSegue(withIdentifier: "toVC4")present(vc, animated: true, completion: nil)

  • let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "VC4") self.present(controller, animated: true, completion: nil)

  • 在VC1中使用协议调用func,但失败。

我肯定会缺少一些东西,如果有人可以提供代码示例来解决此问题,我将非常感激。

1 个答案:

答案 0 :(得分:1)

您可以在弹出按钮的操作中尝试此操作

self.dismiss(animated:true) {
   if let nav = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
      let vc1 = storyboard!.instantiateViewController(withIdentifier: "MenuId")
      let finalVC = storyboard!.instantiateViewController(withIdentifier: "finalId")
      nav.setViewControllers([vc1,vc4],animated:true) // set it to false if you want 
   }
}