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.