19

In the main screen of my iOS application I have a table view populated with a list of users from a web service, what I want to do is to show the table, and over it a modal view controller. I have everything set up, but I don't know how to present my "ModalVC" programatically from the main screen, and to do it after the table was populated? The code below is for presenting a normal view controller programmatically.

let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("ModalVC")
self.showViewController(vc as! UIViewController, sender: vc)
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3188157
  • 209
  • 1
  • 2
  • 5
  • 1
    Though this may be a duplicate, it is not a duplicate of the linked question: "Instantiate and Present a viewController in Swift" – timeSmith Jun 22 '19 at 07:43

1 Answers1

39

Presenting a view controller of class name ModalVC programmatically

let modalVC = ModalVC.instantiateFromStoryboard(self.storyboard!)
self.presentViewController(modalVC, animated: true, completion: nil)

Swift 3:

let modalVC = ModalVC.instantiateFromStoryboard(self.storyboard!)
self.present(modalVC, animated: true, completion: nil)
Duncan Babbage
  • 19,972
  • 4
  • 56
  • 93
Lukas
  • 3,423
  • 2
  • 14
  • 26