I've changed searchDisplayController with searchController for ios 8 support in my app where i use Objective-C.
it works perfectly at the first try, but whenever i click on cancel button on search bar, after animation completes, my search bar disappears. I Do not want it to disappear, whenever i go back to main screen and come back to the search bar screen it appears perfectly.
I've already tried to place search bar outside of the tableview in storyboard but doesn't work. I also tried almost every solution in the web that i can find.
EDIT: i've tried same code block in another .m file and it worked fine within that screen, something overrides-reloads the tableview after cancel button i assume but i couldn't find what it is. What can it be? What am i missing?
EDIT.2: tableview reloadData function makes it dissappear, still no solution for this.
Here are the codes about the searchbar
- (void)viewDidLoad {
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
[self.searchController.searchBar sizeToFit];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.searchController.searchBar setTranslucent:NO];
[self.searchController.searchBar setBackgroundColor:_themeColor];
}
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString = searchController.searchBar.text;
[self searchForText:searchString];
[self.tableView reloadData];
}
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.searchController];
}
- (void)searchForText:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchController.searchBar
selectedScopeButtonIndex]]];
}