user1679671
user1679671

Reputation:

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.

Upvotes: 2

Views: 1097

Answers (4)

Bala Murugan
Bala Murugan

Reputation: 47

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...

Upvotes: 0

Justin Ramos
Justin Ramos

Reputation: 116

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

Upvotes: 3

Zeke
Zeke

Reputation: 134

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.

Upvotes: 0

Malloc
Malloc

Reputation: 16276

I suggest nesting all your navigation stack under a UINavigationController, then it would be as easy as invoking the popToRootViewControllerAnimated: method.

Upvotes: 0

Related Questions