Hiding UISearchBar in UITableView

Note: This is a duplicate of this post... I can't seem to reply on the old forums (perhaps due to the recent archiving).


Hi,

I have a UISearchBar in a UITbableView. I'm usig AutoLayout.


Note: Also, can't seem to insert an image in the new forum ... here's a link to the image from my old post.


I would like to hide the search


Bar until my search button (not shown) is touched.


How can I hide and show the searchBar as needed?


Using the active property as suggested by KMT doesn't really work. The only thing this appears to do is just change the focus to/from the search bar but it doesn hide.


Thanks!

OK. I figured out what was happening. I dragged Search Bar and Search Display Controller from the IB object library into my XIB thinking it as UISearchController. The old stuff is deprecated and I figured IB would only be supporting the new UISearchController but it doesn't. If you want to use UISearchController (preferred for iOS 8+) then you have to add it programmatically.


So I did and it works rather well; except for one thing: on start of my app part of the search bar appears to be underneath my section title.


The UISearchController is configured as shown here:

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = false;
    self.searchController.hidesNavigationBarDuringPresentation = true;
    self.searchController.searchBar.delegate = self;
    self.searchController.searchBar.returnKeyType = UIReturnKeyDone;
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.definesPresentationContext = YES;
    [self.searchController.searchBar sizeToFit];


Still can't seem to put an image into the forum so I can't put a screenshot.


Any ideas on how to correct this problem?


Thanks!

Hiding UISearchBar in UITableView
 
 
Q