ios - 搜索栏不会出现在 ios 中

标签 ios uisearchbar

我有一个页面 Controller ,我在其中添加了两个 TableView 。在添加的每个 TableView 搜索 Controller 标题中,viewForHeader 方法也返回“最近”和“其他” View 。

我的问题是点击搜索栏后搜索栏没有出现。 它似乎向上移动,我看不到我在那里输入的内容。 搜索栏可能隐藏在“连接”、“消息”选项卡后面。

当键盘成为第一响应者时,如何使搜索栏保持在同一位置? 任何帮助将不胜感激。

enter image description here

最佳答案

你是否在 ViewDidLoad 中使用了以下代码行

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

[self.view bringSubviewToFront:searchBarRef]; // add this line where ever u need..!

-(void)loadSearchBar {

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;

    self.tableView.tableHeaderView = searchBar; 

}

ViewDidLoad 调用此 loadSearchBar 方法。

这会将搜索栏添加到 TableView

关于ios - 搜索栏不会出现在 ios 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34312614/

相关文章:

objective-c - iOS:performSelectorOnBackground/MainThread:不更新标签

ios - Xcode 5.1 + iOS 7.1 上的代码签名损坏

当 UISearchController 处于事件状态时,iOS 9 searchBar 从表标题 View 中消失

ios - UISearchBar 的范围栏在 iOS 7 中没有显示?

ios - 如何根据ios中搜索到的项目调整图像?

ios - 如何快速验证电子邮件地址?

ios - UIPanGestureRecognizer 如何获取相对于 [gestureRecognizer View ] 的触摸坐标

ios - iPhone5 的 Xcode 限制把我搞砸了

ios - UISearchBar barTintColor 没有隐藏在 iOS 7.1 中

ios - 如何知道在 uisearchbar 中连续打字以及在 ios 中停止打字