Reputation: 2214
I have a customized UISearchBar that I want to display in self.navigationItem.titleView. I have no problem getting it in there and looking the way I want it to but I think something is wrong with how I connect it with UISearchDisplayController.
Here is the UISearchBar and UISearchDisplayController in viewDidLoad:
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0,0.0,200.0, 22.0)];
searchBar.barStyle = UISearchBarStyleDefault;
searchBar.showsCancelButton = NO;
searchBar.placeholder = @"Search";
searchBar.delegate = self;
self.navigationItem.titleView = searchBar;
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDelegate = self;
searchDisplayController.searchResultsDataSource = self;
At this point the search function is not actually working. If I add [searchDisplayController setDisplaysSearchBarInNavigationBar:YES];
the search function now works but it messes up all the style I that I had added to searchBar
.
Edit: Additional information: looks like [self.searchDisplayController.searchResultsTableView reloadData];
is not getting called. I have the following implemented:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
For some reason if I don't call [searchDisplayController setDisplaysSearchBarInNavigationBar:YES];
then the data is not reloaded. Perhaps I am missing a method.
Upon searching it looks like - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
gets called and tableView == self.searchDisplayController.searchResultsTableView
is true, but it does not proceed to call - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Upvotes: 1
Views: 137
Reputation: 2214
Well, I think the only way to get it to work is to embed UISearchBar into a UIView, I'm okay with the style now although I have been able to make it exactly the same.
Upvotes: 1