Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presenting Modal View Controller programmatically in Swift [duplicate]

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)
like image 962
user3188157 Avatar asked Nov 12 '15 22:11

user3188157


1 Answers

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)
like image 85
Lukas Avatar answered Sep 30 '22 19:09

Lukas