I have one ViewController, I switch to it programmatically from an tableviewcell with the following function.
private func switchView(identifier : String){
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: identifier) as UIViewController
self.present(vc, animated: true, completion: nil)
}
}
After a while I need to switch back to the original state, so I call switchView with the same view again. The only problem is that a lot of stuff stays active in the previous ViewController.
How can I dismiss the previous ViewController with all of its contents?