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];
}
You need to call this when you come back from DetailListController
to your view controller (encapsulating in main thread for safety):
dispatch_async(dispatch_get_main_queue(), ^{
self.searchController.active = NO;
});
You can also call this in viewWillDisappear:
of your current view controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With