         if segue.identifier == "presentDetailedNoteView" {
             if let destinationViewController = segue.destinationViewController as? NotesDetailViewController {
                 if let indexPath = tableView.indexPathForSelectedRow {
-                    destinationViewController.note = notes[indexPath.row]
+                    destinationViewController.note = (searchController.active && searchController.searchBar.text != "") ? searchResults[indexPath.row] : notes[indexPath.row]
                 }
             }
         }

    func controllerDidChangeContent(controller: NSFetchedResultsController) {
        tableView.endUpdates()
    }
    
//    override func viewWillAppear(animated: Bool) {
//        super.viewWillAppear(animated)
//        
//        if let notes = Note.getAllNotes() {
//            self.notes = notes
//            self.tableView.reloadData()
//        }
//    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if searchController.active && searchController.searchBar.text != "" {
            return searchResults.count
        } else {
            return notes.count
        }
    }
    
    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        if searchController.active && searchController.searchBar.text != "" {
            return false
        } else {
            return true
        }
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("NoteTableViewCell", forIndexPath: indexPath) as! NoteTableViewCell
        
        let note = (searchController.active && searchController.searchBar.text != "") ? searchResults[indexPath.row] : notes[indexPath.row]
        
        // Configure the cell...
        cell.titleTextLabel.text = note.title
        cell.contentTextLabel.text = note.content
        cell.backgroundColor = UIColor.clearColor()
        
        return cell
