我有一个UISearchBar
可以在Master-Detail VC设置上正常工作。当UISearchBar
中的MasterViewController
处于活动状态时,会显示正确的单元格,但是当我单击要转移的单元格时,它会提取错误的索引。
如果UISearchBar
处于活动状态,则显示的单元格是filteredObjects
的索引(请参阅下面的变量声明)。
我知道我需要放一个" if"我的prepareForSegue中的陈述。我知道"什么"我需要做,但我不知道如何做。有人有想法吗?
这是我的话:
// 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
}
}
这是我的DetailViewController:
var detailViewController: DetailViewController? = nil
这是我面向UISearchController的属性
var searchController: UISearchController!
var searchPredicate: NSPredicate?
var filteredObjects : [Note]? = nil // <--I want it to go to the index of the filteredObject.