0

I have to force user to go back to the home screen when the app becomes foreground from background. In that case I'll have to create an unwind segue in each and every view controller. Instead what I'm trying to do is, create a parent class for the view controllers and perform the segue. By doing this I can avoid adding unwind segues for every view controller from the storyboard.

I need a way to create an unwind segue from the code instead of creating from Storyboard.

Thanks in advance.

LIH
  • 933
  • 2
  • 10
  • 25

1 Answers1

2

Since, you need to go to Home Screen, which i suppose should be the root controller of your UINavigationController.

For that simply use:

//THIS WILL POP NAVIGATION CONTROLLER TO ROOT CONTROLLER

navigationController?.popToRootViewControllerAnimated(true)
gunjot singh
  • 2,578
  • 20
  • 28