old root view controller not removed when assigning new root view controller
i want to reload the app from its beginning ,but i notice that the old root view Controller not removed from view hierarchy
private func reset() {
guard let window = UIApplication.shared.delegate?.window
else { return }
window?.rootViewController = UIStoryboard.init(name: "Main", bundle: nil).instantiateInitialViewController()
UIView.transition(with: window!, duration: 2, options: .transitionCrossDissolve, animations: {
}, completion: nil)
}
You can try removing the subviews and the root view before assigning the new root view controller
for (UIView* subView in self.window.rootViewController.view.subviews)
{
[subView removeFromSuperview];
}
[self.window.rootViewController.view removeFromSuperview];
This is apparently a know issue in iOS You can see the Detailed Description here