title: Unexpectedly found nil while unwrapping an Optional value while opening UIViewController
body: <p>I'm doing a simple tableview app with swift, in which you open a new view controller programatically after clicking on a table row:</p>
  
  <pre><code>class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
  //GLobals
  @IBOutlet weak var table: UITableView!
  //Table View Data
  
  let cats :[String] = ["Gala","Vito","Odin","Ema"]
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      table.delegate = self
      table.dataSource = self
  }
  
  // MARK:  UITextFieldDelegate Methods
  func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return cats.count
  }
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = table.dequeueReusableCellWithIdentifier("CustomTextCell", forIndexPath: indexPath) as! UITableViewCell
  
      let row = indexPath.row
      cell.textLabel?.text = cats[row]
  
      return cell
  }
  
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
      tableView.deselectRowAtIndexPath(indexPath, animated: true)
  
      let row = indexPath.row
      let cat : String = cats[row];
      println(cat)
  
      //Save cat for detail view
      var defaults = NSUserDefaults.standardUserDefaults()
      defaults.setObject(cat, forKey: "cat")
      defaults.synchronize()
  
  
      let detail:Detail = Detail();
      self.presentViewController(detail, animated: true, completion: nil);
  }
  }
  </code></pre>
  
  <p>The code in the detail view is the following:</p>
  
  <pre><code>class Detail: UIViewController {
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.view.backgroundColor = UIColor.whiteColor()
  
      let defeaults = NSUserDefaults.standardUserDefaults()
  
      let cat = defeaults.stringForKey("cat")
  
      var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
      label.center = CGPointMake(160, 284)
      label.textAlignment = NSTextAlignment.Center
      label.text = cat
  
      self.view.addSubview(label)
  }
  
  override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent) {
      let home:ViewController = ViewController()
      self.presentViewController(home, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>However when the app goes back to ViewController I'm having "unexpectedly found nil while unwrapping an Optional value
  "</p>
  
  <p><img src="https://i.stack.imgur.com/Retcs.png" alt="the error"></p>
  
  <p>I have try some of the other answers to this problem including, warping with if == nil some of the values, but I still can't find what is the problem. </p>
  
  <p>I'm assuming the UIViewController is not loading the UITableViewDelegate and UITableViewDataSource again, but I don't understand why... and how would you load them from another view anyway? </p>