简体   繁体   English

如何从另一个位置关闭 viewController

[英]How to dismiss a viewController from another location

I have a file where i define how a controller should look and define constraints and other things, here i also declare a addtarget on one of buttons like below我有一个文件,我在其中定义 controller 的外观和定义约束和其他内容,在这里我还在下面的按钮之一上声明了 addtarget

 nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside)

and define the method, now every thing works but on the controller page the code to dismiss the modalView does not respond, some how any variation of dismiss code called from view file does not work on the controller, ever thing else works but not dismiss并定义方法,现在一切正常,但在 controller 页面上,关闭 modalView 的代码没有响应,一些从视图文件调用的关闭代码的任何变体在 controller 上不起作用,其他任何东西都有效但不关闭

@objc func nextButtonTapped()
       {


           let index = childController.currentIndex
               print(index)
               switch index {
               case 0...1:

                   childController.forwardPage()


               case 2:
                
                //  dismiss(animated: true, completion: nil)
                //diss.getDisMiss()
                self.presentingViewController?.dismiss(animated: true, completion: nil)
                  
                
               default:
                   break

               }
        
        updateUI()


       }

What you can try is.你可以尝试的是。

self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM