Dismiss and Present View Controller in Swift

前端 未结 5 668
生来不讨喜
生来不讨喜 2020-12-09 11:52

Hi I\'m trying to present a viewcontroller and dismiss my current modal view but this code is not working

self.dismissViewControllerAnimated(true, completion         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 12:25

    You have to get the viewController which presented self (current ViewController). If that view controller is rootViewController, then you can use the code below, if not then query it based on your view controller hierarchy.

    if let vc3 = self.storyboard?.instantiateViewController(withIdentifier: "vc3") as? ViewController3 {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window?.rootViewController!.present(vc3, animated: true, completion: nil)
    }
    

提交回复
热议问题