4

我的 UISearchDisplay 有问题,我有一个视图控制器,里面有一个带有 uisearchdisplay 的 tableview,在 iPhone 上一切正常,而在 iPad 上我有一个小问题。我将视图控制器添加为子项:

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

但是当我点击搜索栏时,我得到了这个:

在此处输入图像描述

搜索栏上方的空格,错误在哪里?这里是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];

另外,如果我尝试使用

[self.searchDisplay setDisplaysSearchBarInNavigationBar:YES];

searchdisplay 不工作,过滤方法是好的,但 rable 没有刷新(并且没有黑色/透明背景)

4

3 回答 3

3

解决方案在这里!

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];
}
于 2013-10-22T21:57:42.110 回答
0

这段代码帮助了我!

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

}
于 2014-09-20T16:15:53.640 回答
0

为我修复:

- (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];
}
于 2016-03-30T15:50:43.260 回答