Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset seachDisplayController View to original state programatically

I have the UISearchDisplayController page view as follows (original state)

enter image description here

After clicking on the searchbar and typing some search term, I get a list of results in the table

enter image description here

After clicking on an entry in the table, a new viewController is displayed on top of the stack

enter image description here

My intention is that on the click of the cancel button (on top left), the root view will display the original state of the searchDisplay controller

enter image description here

This is what I have tried

In my cancel method (triggered when I click on the top left hand cancel button)

- (void)cancel
{
  [self dismissViewControllerAnimated:YES completion:NULL];
  [self searchBarCancelButtonClicked:self.searchDisplayController.searchBar];
}

And in the searchbar delegate method I did this

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    self.searchBar.showsCancelButton = NO;

    [self.searchBar resignFirstResponder];
    self.searchBar.text = @"";
    searchDisplayController.searchResultsTableView.hidden = YES;
    [self searchDisplayControllerWillEndSearch:self.searchDisplayController];
}

All I manage to achieve after clicking on the cancel button is this

enter image description here

The original tableview seems to be missing (appears only if I click on the page)

How can I modify my methods to revert the search to its' original state?

like image 625
Zhen Avatar asked Feb 18 '23 02:02

Zhen


1 Answers

Try [searchDisplayController setActive:NO animated:NO]

This should hide the search table.

like image 69
Léo Natan Avatar answered May 14 '23 17:05

Léo Natan