我在UISearchDisplay上遇到问题,我在内部有一个带有uisearchdisplay的tableview的viewcontroller,在iPhone上都可以正常工作,而在iPad上,我有一个小问题。
我将viewcontroller添加为子控件:
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无法正常工作,过滤方法还可以,但寓言没有刷新(并且没有黑色/透明背景)
最佳答案
这里解决!
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];
}