Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

Segue from TableView to Details view

Wade Cantley


The goal is simple to move data from a selected cell in a table view to a details related view.
Here is the code.

You can explicitly build the new view controller and pass the data in when you detect that a row is selected:


override func tableView(tableView: UITableView!, didSelectRowAtIndexPath path: NSIndexPath!) {
    let entry = news[path.row] as NSDictionary
    let url = entry["link"] as NSString
    let secondViewController = 
        self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController")
        as SecondViewController

    // pass the relevant data to the new sub-ViewController
    secondViewController.url=url;
    // tell the new controller to present itself
    self.navigationController.pushViewController(secondViewController, animated: true)
}

and in SecondViewController.swift, add a variable to hold the relevant data.


class SecondViewController: UIViewController {
    var url: String? = ""
}