IOS returns to the rootViewController root controller view, and ios View Controller Switches
Directly Add code
-(Void) backToRootViewController {UIViewController * vc = [MainViewController instance]. navigationController. visibleViewController; if ([vc isEqual: [MainViewController instance]) return; if (vc. presentingViewController) {[vc dismissViewControllerAnimated: NO completion: ^ {[self backToRootViewController] ;}];} else {[vc. navigationController popViewControllerAnimated: NO]; [self backToRootViewController];}
The above Code requires an Instance Object of the root controller. The principle is to iteratively bring up the stack top Controller until the root controller is returned. No animation is shown here. If you want to display an animation, you need to use CATransaction to control the popViewControllerAnimated animation and then execute the call again. Otherwise, an error will certainly occur. I personally don't think it is necessary. It may take several seconds for no one to return to the home page.
Good luck!