Search Bar does not receive touches

| | August 5, 2015

the search bar does not receive touches when scrolled but does receive when it is on the original contentOffSetI have a search bar implemented and it ‘sticks’ to the tableView. Now, after the tableView starts scrolling, the searchBar does not receive touches and become the first responder, instead, the cell behind it does and navigates to the next view. What can I do to make the searchBar receive touches?

Code for keeping it static:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    UISearchBar *searchBar =;
    [[self.tableView.tableHeaderView superview] bringSubviewToFront:self.tableView.tableHeaderView];
    CGRect searchBarFrame = searchBar.frame;
    if (self.inSearchMode)

        searchBarFrame.origin.y = 0;

        searchBarFrame.origin.y = MAX(0, scrollView.contentOffset.y +;
    } = searchBarFrame;

2 Responses to “Search Bar does not receive touches”

  1. You could put the searchBar in the table header and implement the – (void)scrollViewDidScroll:(UIScrollView *)scrollView delegate method for the tableView. Doing something like this should work:

    -(void) scrollViewDidScroll:(UIScrollView *)scrollView {
        searchBar.frame = CGRectMake(0,MAX(0,scrollView.contentOffset.y),320,44);

    If you used the searchDisplayController, you would access the searchbar using self.searchDisplayController.searchbar.

    Note: user your code and try to impliment this method .

  2. If you think about it, the table header frame will be outside the table bounds when you scroll.
    Try to add it as a subview to the tableView directly and set its frame relative to tableView bounds to keep it sticky.

Leave a Reply