In my app I have the following setup:
tableView has a UISearchController and a search bar is a table header view
_tableView.tableHeaderView = _searchController.searchBar;
What I want to achieve is:
when the search bar is not showing the table looks like that bar was never there ( there is no empty header cell or anything like that)
Any kind of help is highly appreciated!
Figured this myself, maybe not the most optimal solution, but if anyone has better idea I would happily accept is as an answer.
-(void)searchButtonDidTap:(UIButton*)aButton
{
if (!_searchController){
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
_searchController.searchResultsUpdater = self;
[_searchController.searchBar sizeToFit];
_tableView.tableHeaderView = _searchController.searchBar;
_searchController.delegate = self;
_searchController.dimsBackgroundDuringPresentation = NO;
self.definesPresentationContext = YES;
_searchController.active = NO;
_searchController.searchResultsUpdater = self;
_searchController.dimsBackgroundDuringPresentation = NO;
self.definesPresentationContext = YES;
_tableView.tableHeaderView = _searchController.searchBar;
_searchController.searchBar.delegate = self;
}
else
{
_searchController.active = NO;
[_searchController removeFromParentViewController];
_searchController = nil;
_tableView.tableHeaderView = nil;
}
[_tableView reloadData];
}