I'm trying to preload UISearchBar with a searchString.
In the current set up. I'm using UISearchDisplayController in the UITableViewController.
The First approach I use is set the search string in the following method:
- (void) presetSearchDisplayControllerWithString:(NSString*)searchString{
[self.searchDisplayController setActive:YES animated:NO];
[self.tableView setContentOffset:CGPointMake(0, 0)];
self.searchBar.text = searchString;
self.searchFetchedResultsController = [self createFetchedResultsControllerWithSearchTerm:searchString];
}
It works. UISearchbar shows the search string, original tableView and TableViewIndex are hidden. But if I press cancel button on the searchBar it crashes:
* Assertion failure in -[UISearchDisplayController setActive:animated:], /SourceCache/UIKit_Sim/UIKit-2372/UISearchDisplayController.m:682 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'search contents navigation controller must not change between -setActive:YES and -setActive:NO'*
The Second varian is not working either
- (void) searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[self.searchDisplayController.searchBar setText:@"rune"];
}
Well, it works if you tap in the searchbar. But until you've done it, it shows just a regular tableView.