Dismiss calling modal after calling a modal [SOLVED]


I’m trying to call a modal from a modal then dismiss the calling modal. Can someone please help me. Thanks in advance! :slight_smile:

let storyboard = UIStoryboard(name: "VehicleEntry", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "VehicleEntryViewController")
            vc.view.backgroundColor = UIColor(white: 0, alpha: 0.5)
            vc.modalPresentationStyle = .custom
            self.present(vc, animated: false, completion: {
                vc.view.superview?.isUserInteractionEnabled = true
                vc.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.onClose)))


you want to dismiss the calling modal then keep the top most modal?


yes!. :heart_eyes:

but when i tried to dismiss the previous modal in the called modal, error occur like ‘Found nil when unwrapping an optional value’ or something like that. the error is line in ‘view.layer.cornerRadius = 5’.


this is the end result right?



yup! :slight_smile:

i have also tried dismiss then present in completion and vice versa.


how about dismiss the 1st modal which will trigger to open the 2nd one?

From the rootVC have you tried?

[firstModal dismissViewControllerAnimated: completion: {


not yet. is that on swift? can you give me a sample on how to use that? :frowning:


Is this what you are trying to do?



yeah!! :star_struck:

how to do that?!!

why is it not working on me?? :frowning:


I upload the demo project on my github


what is your github link?


I just pushed it here https://github.com/iAmNaz/StackedModalDemo.git


Thanks!! :heart_eyes: