As shown in this picture, I have root navigation controller which has its root viewcontroller as VC1.
In VC2 i present Modally with the option: Over Current Context in order to get the Blur effect.
In VC4, User has the option to navigation back to the root viewcontorller VC1. which is shown in the large Red Arrow.
I tried 2 ways:
First:
In VC4:
func popToRoot(){
self.dismiss()
self.navigationController?.popToRootViewController(animated: animated)
}
The Problem: This code navigation back to VC2.
Second:
I tried to have a public static boolean
which i set it true if user wants to go back to VC1
VC1:
class VC1: UIViewController {
public static var shouldGoBackToMainRoot = false;
override func viewDidAppear(_ animated: Bool) {
VC1.shouldGoBackToMainRoot = false
}
}
VC2:
class VC2: UIViewController {
override func viewDidAppear(_ animated: Bool) {
if VC1.shouldGoBackToMainRoot {
self.dismiss()
self.navigationController?.popToRootViewController(animated: animated)
return
}
}
}
VC4:
class VC4: UIViewController {
// .. other code ...
func onGoBackToRootClicked() {
VC1.shouldGoBackToMainRoot = true
self.dismiss()
self.navigationController?.popToRootViewController(animated: animated)
}
}
The Problem: In VC2
: viewDidAppear
and viewWillAppear
will not get called since i presented VC3
with Over Current Context
.
NOTE: Removing Over Current Context will let VC2
's viewDidAppear function to get called, but i will lose the Blur effect. which is not what i want.
Question: How to navigate from VC4 to VC1 without losing the Blur effect ?