I'm using UISPlitViewController in order to show categorized data on the screen. I implemented a search method on master view controller and the flow of data is fine on the iPhone screen, but on the iPad, portrait and landscape, It does work as I want.
I have create a segue (the black arrow points it) to detail controller but it loads data into master view controller.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let object = categoryID[indexPath.row]
let controller = (segue.destination as! UINavigationController).topViewController as! DetailTableViewController
controller.detailItem = object as Int?
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
}
//this is the problem!
}else if segue.identifier == "showSearchDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let object = searchResultDrugsID[indexPath.row]
let controller = (segue.destination as! UINavigationController).topViewController as! DrugDetailsTableViewController
controller.detailItem = object as Int?
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
And here is where the problem lies, I want to load data in detail view controller when user clicks on search results:
Too many Navigation Controllers, too many segues.
From the storyboard screen shot, I can only assume that you may have mixed and matched
detail
view controllers improperly. Specifically, the one with the black arrow shouldn't be there.You probably do not need (and shouldn't have) both a
"showDetail"
and a"showSearchDetail"
: searching is merely reducing the scope of what's available in the Master view, which is the expected user experience.An excellent resource on the topic is Candy Search from raywenderlich.com, with an excellent example and tutorial.
Creating a default Master-Detail project from Xcode yields this structure:
To add a
UISearchController
to that, build it programmatically in your masterUITableViewController
:and filter the results from the
UISearchResultsUpdating
delegate:Also, details segues should "Show Details"