3

I currently have a UISearchBar and UISearchDisplayController implemented as:

- (void) viewDidLoad {

 videoList = [[NSMutableArray alloc]init];

 //Add the search bar
 aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
    [aSearchBar sizeToFit];
 aSearchBar.delegate = self;
    aSearchBar.placeholder = @"Search YouTube...";

    self.tableView.tableHeaderView = aSearchBar;

    searchDC = [[UISearchDisplayController alloc] initWithSearchBar:aSearchBar contentsController:self];

    [self performSelector:@selector(setSearchDisplayController:) withObject:searchDC];

    searchDC.delegate = self;
    searchDC.searchResultsDataSource = self.tableView.dataSource;
    searchDC.searchResultsDelegate = self.tableView.delegate;

    [aSearchBar release];
    [searchDC release];

}

When the user types something and hits search, a tableView appears on top of the tableView in the background.

Is there anyway of hiding this 'searchResults tableView' ? (I just want the background table to hold the data..which it currently does).

i.e. is there a property? e.g. searchDisplayController.tableView.visible=NO or similar?

3 Answers 3

12

This however doesn't dismiss the search interface (search bar and "cancel" button). The next code does it:

    [self.searchDisplayController setActive:NO animated:YES];
2
searchDC.searchResultsTableView.hidden=YES;
1
  • 2
    Hiding the search results table allows user interaction with the underlying (main) view and that (main) view is not "dimmed". Apr 16, 2012 at 15:43
0

[[UISearchBar alloc] initWithFrame:CGRectZero];

don't use CGRectZero self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.table.frame.size.width, 44)];

try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.