Adding a UISearchBar to the table header as a subtask

I am trying to add a custom title in UITableViewthat has several buttons and UISearchBar. The problem is that when I try to use searchBar, I get a message:

setting the first responder view of the table but we don't know its type (cell/header/footer)

Does anyone encounter such a problem?

+5
source share
2 answers

You add to the table through:

[self.tableView addSubview:customView]

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

self.tableView.tableHeaderView = customView
-1
source

Just follow the simple steps here.

  • create a property for mySearchBar in the .h file and synthesize it.
  • viewDidLoad/viewDidAppear ( )
  • , ...

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

All Articles