I'm using a UISearchController inside ma UIViewcontroller
that contains a UITableView
, I do this in viewDidLoad
:
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = NO;
when I push a button in the navbar i do this:
self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top);
self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar becomeFirstResponder];
all works fine, but when I push a UIViewController
from a row in the UITableView
results the UISearchBar
stay there and display also on the content of the other view, how can i dismiss when I push a view and present when I go back to see the result of the UITableView
?
thanks
EDIT:
this is the code of the method didSelectRowAtIndexPath
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailListController *detailList = [[DetailListController alloc] init];
[self.navigationController pushViewController:detailList animated:YES];
}
Try this standard way suggested by apple:
Declare the properties:
and here comes the interesting part: Use the below code to restore the status when you comeback from the detail view
Put this code in your
viewDidLoad
:You need to call this when you come back from
DetailListController
to your view controller (encapsulating in main thread for safety):You can also call this in
viewWillDisappear:
of your current view controller.After trying to deal with the same problem for a few days, realized that the proper way of doing this is to have a navigation controller that contains everything in the search hierarchy
like this :
when you push details controller, you push it into navigation 1, showing its navigation bar at the same time.
This leaves search stack untouched and ready to work when you hit "back" on the detail page