Here is a little trick I did;) Don't make your SearchBar a subspecies of your UITableView. Just add them both to the nib file, and connect them to IBOutlets in your UITableViewController. Then what you are going to do is set the SearchBar as the title view for your table, so you donβt have to worry about overlapping frames and interfering with touch events. Here's how you do it:
Create Property in TableView Header File
@property ( nonatomic, retain ) IBOutlet UISearchBar *searchBar;
Define a header view for your table:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return self.searchBar;
Set height for title or (UISearchBar)
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 44;
That is all you need. Now this may not be the best solution if you have a grouped view of a table or a table with several partitions, but it is a simple solution for a simple table. Otherwise, you will need to adjust the frame of the search bar and the table in the code, because they overlap, and therefore you have problems with touching. Hope this helps!
jerrylroberts
source share