Возможно, проблема в том, что вы используете:
viewController.removeFromParent()
Если вы поставите pop
на V C в стеке, остальные VC будут автоматически удалены.
Попробуйте изменив веселье c на это:
private func PopOrPushToViewController(_ strControllerClass: String) {
// get the list of controllers in the stack
if let vcStack: [UIViewController] = self.navigationController?.viewControllers {
var didPop = false
for vc in vcStack {
// if we find the desired VC already in the navVC's stack of controllers,
// pop to it, set the didPop flag to true, and quit looking
if String(describing: type(of: vc)) == strControllerClass {
self.navigationController?.popToViewController(vc, animated: true)
didPop = true
break
}
}
// if we did NOT pop to the desired VC,
// instantiate it and push it onto the stack
if !didPop {
if let vc = NavigationController.sharedInstance.storyboardViewControllerFromString(strControllerClass) {
navigationController?.pushViewController(vc, animated: true)
}
}
}
}