Dismiss calling modal after calling a modal [SOLVED]


#1

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

#2

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


#3

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’.


#4

this is the end result right?

rootVC->modal->modal


#5

yup! :slight_smile:

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


#6

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

From the rootVC have you tried?

[firstModal dismissViewControllerAnimated: completion: {
present2ndModal()
}


#7

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


#8

Is this what you are trying to do?

stacked-modal


#9

yeah!! :star_struck:

how to do that?!!

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


#10

I upload the demo project on my github


#11

what is your github link?


#12

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


#13

Thanks!! :heart_eyes: