-1

I've created a tabbed application and am able to present a view modally using the code below, however, I'm stuck on dismissing the view and displaying the tab bar and first view controller.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let signUpViewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController") as! SignUpViewController
self.window?.makeKeyAndVisible()
self.window?.rootViewController = signUpViewController
Sami
  • 1,374
  • 1
  • 16
  • 43
  • 1
    You do not present anything modally in your code. You replace whatever is the `rootViewController` in your app (I guess the tab bar controller) with your `signUpViewController`. – André Slotta Sep 25 '18 at 15:20

3 Answers3

0

Inside that signUpViewController do this after giving that tabBarController a storyboard identifier in IB

let tab = storyboard!.instantiateViewController(withIdentifier:"tab") 
UIApplication.shared.keyWindow?.rootViewController = tab

OR

(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = tab
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

You should present your modal vc over you tab bar vc

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let signUpViewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController") as! SignUpViewController
signUpViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
signUpViewController.modalTransitionStyle = UIModalTransitionStyle.coverVertical
self.window.rootViewController.present(myModalViewController, animated: true, completion: nil)

(if self.window.rootViewController - your tab bar view controller)

And in this case you can use dismiss(animated: true, completion: nil) method in modal vc to dismiss it.

Anton Rodzik
  • 781
  • 4
  • 14
0

In your TabBarViewController, do the following when presenting SignUpViewController

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier:"SignUpViewController")
viewController.modalPresentationStyle = .overFullScreen
self.presentViewController(viewController, animated:true)

and when dismissing, simply call the dismiss code from SignUpViewController

e.g. dismissViewControllerAnimated

Noor
  • 967
  • 7
  • 18