简体   繁体   中英

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

 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

@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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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