francesco.venica
francesco.venica

Reputation: 1721

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)

Upvotes: 4

Views: 2215

Answers (3)

Antonioni
Antonioni

Reputation: 578

Fix for me:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self updateSignInButton];

    // Choose #1 or #2
    // #1 Not hiding the search bar
    [self.tableView setContentInset:UIEdgeInsetsZero];

    // #2 Hiding the search bar
    //[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}

Upvotes: 0

ErcanE
ErcanE

Reputation: 1641

This Code helped me!

    if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
    self.edgesForExtendedLayout = UIRectEdgeNone;

}

Upvotes: 0

francesco.venica
francesco.venica

Reputation: 1721

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];
}

Upvotes: 3

Related Questions