Adding UISearchBar into tableView header as subview

2 Solutions Collect From Internet About “Adding UISearchBar into tableView header as subview”

Are you adding to the table via:

[self.tableView addSubview:customView]

If so, that could be your error. Adding subviews to UITableView requires that you add them either as header, footer, or cell explicitly. Try:

self.tableView.tableHeaderView = customView

Just follow the simple steps here..

  1. create a property for mySearchBar in your ‘.h’ file and synthesize.
  2. set its attributes in viewDidLoad/viewDidAppear method (or u can simply do it in the Interface Builder)
  3. Use the following delegate method to set it as the header of your table view…

    – (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {                 
            return self.mySearchBar;