简体   繁体   中英

Redirecting to initial view controller

Is there any way to redirect (push or perform segue etc.) to initial view controller aka rootViewController from appdelegate class? I am using stroryboard btw. Any answers are appreciated.

UP. I am not using navigation controller.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
window.rootViewController = [storyboard instantiateInitialViewController];

我建议将所有导航堆栈嵌套在UINavigationController ,这就像调用popToRootViewControllerAnimated:方法一样容易。

UINavigationController popToRootViewController methods takes you there, if you're using UINav controller.

Other way you can try out: self.window.rootViewController is a reference that might useful.

By Using Swift 4.2

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let window: UIWindow? = (UIApplication.shared.delegate?.window)!
window?.rootViewController = mainStoryboard.instantiateInitialViewController()

Working Perfect...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM