【问题标题】:iOS 8 UISearchController's searchBar overlapping tableVIewiOS 8 UISearchController 的 searchBar 重叠 tableVIew
【发布时间】:2015-02-11 06:23:20
【问题描述】:

我正在练习使用 iOS 8 的新功能 - UISearchController 来显示我的 tableView 和结果。但是奇怪的事情发生了。看起来 searchBar 是透明的。

是的,searchBar 与 tableView 重叠。我在 SO 中搜索了很多,但没有任何帮助。

我在viewDidLoad的实现

self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_myTableView.delegate = self;
_myTableView.dataSource = self;
[self.view addSubview:_myTableView];

self.mySearchController = [[UISearchController alloc] initWithSearchResultsController:nil];
_mySearchController.searchResultsUpdater = self;
_mySearchController.dimsBackgroundDuringPresentation = NO;
_mySearchController.hidesBottomBarWhenPushed = YES;
_mySearchController.hidesNavigationBarDuringPresentation = YES;
_mySearchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
[_mySearchController.searchBar sizeToFit];

self.myTableView.tableHeaderView = self.mySearchController.searchBar;

我错过了什么重要的事情吗?

【问题讨论】:

  • 尝试添加 [_myTableView setContentOffset:CGPointMake(0, 44)]
  • 尝试使用 rect (0, 0, tableView.frame.size.width, 44) 创建一个 UIView,将搜索栏放在那里,然后将此视图设置为 tableHeaderView
  • @NilsHolgerson 两个都试了,不行。
  • @anatoliy_v 试试,好像搜索栏是透明的

标签: ios objective-c iphone uitableview uisearchbar


【解决方案1】:

这是因为你设置了_mySearchController.searchBar.searchBarStyle = UISearchBarStyleMinimal。根据苹果的documentation

UISearchBarStyleMinimal - 搜索栏没有背景,搜索栏是半透明的。

尝试删除该行代码或将其设置为 UISearchBarStyleDefault

【讨论】:

    猜你喜欢
    • 2018-07-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    相关资源
    最近更新 更多