I 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.search;
[[self.tableView.tableHeaderView superview] bringSubviewToFront:self.tableView.tableHeaderView];
CGRect searchBarFrame = searchBar.frame;
if (self.inSearchMode)
{
searchBarFrame.origin.y = 0;
}
else
{
searchBarFrame.origin.y = MAX(0, scrollView.contentOffset.y + scrollView.contentInset.top);
}
self.search.frame = searchBarFrame;
}
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.