0

I have a UISearchBar that works properly on a Master-Detail VC setup. The correct cells are displayed when the UISearchBar is active in the MasterViewController, but when I click the cell to segue, it pulls up the wrong index.

If the UISearchBar is active, the cell displayed are the index of filteredObjects (see variable declarations below).

I know I need to put an "if" statement in my prepareForSegue. I know "what" I need to do, but I don't know how. Anyone got ideas?

Here's my segue:

// MARK: - Segues
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetail" {
        if let indexPath = self.tableView.indexPathForSelectedRow() {
            searchDisplayController?.searchResultsDelegate = self
            let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as! NSManagedObject
            let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
            controller.detailItem = object
            controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
            controller.navigationItem.leftItemsSupplementBackButton = true
        }
    }

    if segue.identifier == "addNote" {
        println("segue.identifier is addNote")
        let controller = (segue.destinationViewController as! UINavigationController).topViewController as! AddNoteViewController
    }
}

Here's my DetailViewController:

var detailViewController: DetailViewController? = nil

Here are my UISearchController-oriented properties

var searchController: UISearchController!
var searchPredicate: NSPredicate?
var filteredObjects : [Note]? = nil // <--I want it to go to the index of the filteredObject.
Adrian
  • 16,233
  • 18
  • 112
  • 180
  • 1
    Is this what you are looking for http://stackoverflow.com/a/24490398/1187415 ? – Martin R Feb 27 '15 at 05:55
  • I fiddled with it earlier, but then again, I eat crayons and paste. I can't get it to work, though I understand what it does in a "physics for poets" sense. – Adrian Feb 27 '15 at 06:11

0 Answers0