Search code examples
uisearchbaruisearchdisplaycontroller

UISearchDisplay issue - move down


I have a problem with the UISearchDisplay, I have a viewcontroller with a tableview inside that have a uisearchdisplay, on iPhone all work perfectly, while on iPad I have a little problem. I add the viewcontroller as child:

self.tableViewController = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
    self.tableViewController.obj = nil;
    self.tableViewController.isSearch = YES;

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.tableViewController];
    self.navigationController.view.frame = self.tableViewContent.bounds;

    [self addChildViewController:self.navigationController];
    [self.tableViewContent addSubview:self.navigationController.view];

but when I click on searchbar I get this:

enter image description here

a blanck space upper the searchbar, where is the mistake? Here the code of uisearchdisplay/uisearchbar

self.searchBar = [[UISearchBar alloc] init];
[self.searchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[self.searchBar setPlaceholder:@"Type a search term" ];
[self.searchBar setTintColor:[UIColor blackColor]];
[self.searchBar setDelegate:self];
[self.searchBar sizeToFit];
[self.tableView setTableHeaderView:self.searchBar];


self.searchDisplay = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
                                                       contentsController:self];
[self.searchDisplay setDelegate:self];
[self.searchDisplay setSearchResultsDataSource:self];
[self.searchDisplay setSearchResultsDelegate:self];


[self.tableView setContentOffset:CGPointMake(0,44) animated:NO];

also, if I try to use

[self.searchDisplay setDisplaysSearchBarInNavigationBar:YES];

the searchdisplay not work, the filter method is ok but the rable is not refresh (and there isn't the black/transparent background)


Solution

  • Here the solution!

    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (version >= 7.0) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
        [self setAutomaticallyAdjustsScrollViewInsets:YES];
        [self.tabBarController.tabBar setTranslucent:NO];
        [self.navigationController.navigationBar setTranslucent:NO];
    }