我有一个UISearchDisplay的问题,我有一个带有tableview的viewcontroller里面有一个uisearchdisplay,在iPhone上完全可以正常工作,而在iPad上我有一点问题。 我将viewcontroller添加为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];
但是当我点击搜索栏时,我得到了这个:
搜索栏上方的空白区域,错误在哪里? 这里是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没有刷新(并且没有黑/透明背景)
答案 0 :(得分: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];
}
答案 1 :(得分:0)
本守则帮助了我!
if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
答案 2 :(得分: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];
}