I have the following code which works under iOS5 for putting a UISearchBar at the top of a UITableView on the iPad :
- (void)viewDidLoad
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGRect searchViewFrame = CGRectMake(33, 33, 264, 45);
UIView *containerSearch = [[UIView alloc] initWithFrame: searchViewFrame];
searchBar = [[UISearchBar alloc] init];
searchBar.barStyle = UIBarStyleDefault;
[containerSearch addSubview: searchBar];
self.tableView.tableHeaderView = containerSearch;
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar
contentsController:self];
searchBar.delegate = self;
searchController.delegate = self;
searchController.searchResultsDelegate=self;
searchController.searchResultsDataSource=self;
[searchBar release];
}
Under iOS6 however this code behaves strangely. When the iPad is started in landscape mode the UISearchBar is offscreen. It does not appear in its correct position until the ipad is rotated to portrait and back to landscape.
Is this just an iOS6 bug or any suggestions as to how it can be fixed ?
Thanks !
Have you tried to init the searchbar with a frame?
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,265,45)];