assigning new rootViewController to window doesn't remove current from view Hierarchy when debugging view hierarchy using xcode

77 views Asked by At

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

There are 1 answers

0
Pooja Kamath On BEST ANSWER

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