1

I have a search bar and a search display controller with the associated methods implemented. In my xib, I have a text field above this search bar. I want the table view that appears to appear below my search bar and not to cover the search bar or the text field above it.

I have tried this:

self.searchDisplayController.searchResultsTableView.frame = CGRectMake(0, 247, 320, 400);

But this doesn't seem to have any effect. How do I set the UITableView position?

OK - with doing this -

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.frame = CGRectMake(0, 200, 320, 400);

}

The table is appearing below the search bar, but for some reason I cannot click the text field above. I think that is happening because said field is still being covered by the table view and the reason I think this is because when I click on the search bar and begin typing a grey area appears that covers everything.

praks5432
  • 7,246
  • 32
  • 91
  • 156
  • That gray area supposed to be overlay UITableView showing search result. Try adding an initial tableView from xib interface and use the synthesized property in your SearchDisplayController methods. – Engnyl Dec 27 '13 at 09:07

2 Answers2

0

try setting frame in controller

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
     if ( [controller.searchBar.superview isKindOfClass: [UITableView class]] )
 {
    UITableView* staticTableView = (UITableView*)controller.searchBar.superview;

    CGRect f = [tableView.superview convertRect: staticTableView.frame fromView: staticTableView.superview];
    CGRect s = controller.searchBar.frame;
    CGRect newFrame = CGRectMake(f.origin.x,
                                 f.origin.y + s.size.height,
                                 f.size.width,
                                 f.size.height - s.size.height);

    tableView.frame = newFrame;
 }
}
Retro
  • 3,985
  • 2
  • 17
  • 41
0

An old question but I thought I'd answer anyway in the hope it might help someone else -I had the same issue and calling scrollRect whenever the search string/results were updated worked - you need a reference to the view controller (self.displayController in this case) which displays the search results.

    [self.displayController.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) 
                                                 animated:NO];
nikkumang
  • 1,615
  • 2
  • 17
  • 34