Add another view controller

Add the view controller:
1. Go to the object library.
2. Search for view controller.
3. Drop it into an empty space in the storyboard.
4. Create a new ViewController file: cocoa touch class, subclass of UIViewController.
5. Assign this new view controller file as the class of the view controller created in the storyboard.


Have it pop up when you click the table view cell:
1. In the left hand side of the screen, click and drag a line from the table view cell to the new view controller.
2. Choose 'show' if you want the view to be stacked on top of it.
3. You can also choose modal.

How to send data from one view controller to another:
1. Click on the line joining the two view controllers. It is a storyboard segue.
2. Give it an identifier at the attribute inspector, for instance: nameOfTheSegue
3. Inside the first view controller class, override the following function and type:
//overriden function - type prepare
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     
        if let id = segue.identifier
        {
            if(id == "nameOfTheSegue")
            {
                let newVC = segue.destination as! VCThatGetsInfo
                newVC.passedString = "Hello World"
            }
        }
     
    }



Comments

Popular posts from this blog

Setting up a playground

Go to another page