I have an UITableView which works perfectly fine. It is nested in a UITabbarController.
I also integrated an UISearchController with a UISearchBar, which lets the user search the content of the UITableView. This also works fine.
When you select one of the TableViewCells, you get to a DetailView.
When you do this without active search, everything works fine, but when you enter a searchterm and you choose a cell from the results, there is no way to get back to the TableView as there is no back button in the top left corner, neither can you use the swipe back gesture.
I may have to add, that I do not specify a separate UITableView for the searchresults:
self.searchController.searchBar.delegate = self
self.searchController.searchResultsUpdater = self
self.tableView.tableHeaderView = self.searchController.searchBar
self.definesPresentationContext = true
I define the SearchController like this:
var searchController: UISearchController = {
let controller = UISearchController(searchResultsController: nil)
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
return controller
}()
I thought, that maybe I have to put a UINavigationController into the UITabbarController and set my TableView as its RootViewController, but then I had the problem, that the SearchBar was hidden behind the NavigationBar...
EDIT (@ryantxr): my didSelectRowAtIndexPath:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
in cellForRowAtIndexPath
there is no difference between search and no search as the cells look the same. This is also the reason, why I don't use two different segue yet.
But you are right, I don't use different segue when using search and no search. The only segue used when a cell is clicked is setup in the storyboard and in prepareForSegue
I set the attributes of the target UIViewController, which also works fine.
Turns out that the problem was this little piece of code in the UITableViewController which contains the UISearchController was responsible for this:
self.definesPresentationContext = true
by deleting this, the result view controller was shown correctly and the navigationbar did not disappear so it was possible to go back to the searchresults ect...