0

I am required to create two UISearchBars in my tableView. I want both of them of equal width on top of the table (side-by-side).

I have created two outlets of UISearchBar, and property and de alloc for them. I am finding it hard to place (I mean fit) both of them in the view. I get only one search bar expanding to the FULL width of the screen. How do I fit two ?

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 4, 45)];
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(4, 0, 4, 45)];

searchBar.placeholder = @"School Name";
zipSearchBar.placeholder=@"Zip";

searchBar.delegate = self;
zipSearchBar.delegate = self;

self.tableView.tableHeaderView= zipSearchBar;
self.tableView.tableHeaderView= searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
Legolas
  • 12,145
  • 12
  • 79
  • 132

1 Answers1

3

You are simply reassigning it when you do self.tableView.tableHeaderView= searchBar;. You will have to build a view that contains both the search bars and then set it to the table's header view. Something like this,

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(200, 0, 120, 45)];

searchBar.placeholder = @"School Name";
zipSearchBar.placeholder=@"Zip";

searchBar.delegate = self;
zipSearchBar.delegate = self;

UIView * comboView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
[comboView addSubview:searchBar];
[comboView addSubview:zipSearchBar];

self.tableView.tableHeaderView= comboView;
[comboView release];
Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105