title: iOS Fix search bar on top of the UITableViewController?
body: <p>I'm adding search bar on table header and floating it in <code>scrollViewDidScroll</code> method, but when i scroll without click on search bar(i.e. i go to the view and do scroll) then search bar doesn't stay on top but it scroll up with table however once i click on search bar and click cancel button on search bar and then if i scroll the table, search bar stays on top.here is my code-</p>
  
  <pre><code>-(void)viewDidLoad {
      [super viewDidLoad];
  
      UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
      searchBar.delegate = self;
  
      searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
      searchDisplayController.delegate = self;
      searchDisplayController.searchResultsDataSource = self;
      searchDisplayController.searchResultsDelegate = self;
  
      UIView *tableHeaderView = [[UIView alloc] initWithFrame:searchDisplayController.searchBar.frame];
      [tableHeaderView addSubview:searchDisplayController.searchBar];
      [tableView setTableHeaderView:tableHeaderView];
  
      isSearching = NO;
  }
  
  -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  
      UISearchBar *searchBar = searchDisplayController.searchBar;
      CGRect searchBarFrame = searchBar.frame;
  
      if (isSearching) {
          searchBarFrame.origin.y = 0;
      } else {
          searchBarFrame.origin.y = MAX(0, scrollView.contentOffset.y + scrollView.contentInset.top);
      }
  
      searchDisplayController.searchBar.frame = searchBarFrame;
  }
  
  - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
      isSearching = YES;
  }
  
  -(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
      isSearching = NO;
  }
  </code></pre>
  
  <p>Note that I'm using <code>UITableViewController</code> sub class and don't want to change it to <code>UIViewController</code>.
  Any help would be appreciated.</p>
  
  <p><strong>Edit:</strong> I also using section header in this <code>UITableViewController</code>, in other <code>UITableViewController</code> there is no section header and this code working fine.Is this a problem with section header and table header together?</p>