So, I'm currently trying to replace the stripped searchDisplayController in one of my projects with a UISearchController, and I ran into this problem.
If no search results (UITableView is empty), the entire ViewController is rejected. This does not happen when the search results are not empty. I do not want me to understand that I am not using the UITableViewController. Instead, I have a regular VC with a UITableView in it.
Here is my code:
var resultSearchController = UISearchController() override func viewDidLoad() { super.viewDidLoad() self.resultSearchController = ({ let controller = UISearchController(searchResultsController: nil) controller.searchResultsUpdater = self controller.dimsBackgroundDuringPresentation = false controller.searchBar.sizeToFit() controller.delegate = self controller.searchBar.delegate = self self.studentTable.tableHeaderView = controller.searchBar return controller })() .... }
Now, if I add this function to the equation, the cancel button always rejects the VC.
func searchBarCancelButtonClicked(searchBar: UISearchBar) { resultSearchController.active = false }
So why exactly does setting searchController.active = false reject the VC? Is it because it uses the same UITableView as VC? I believe that the old searchDisplayController will simply display the UITableView over the one used. If so, is there a way to override the rejectVC function?
source share