键入时搜索栏从视图中消失 [英] Search Bar disappeared from view while typing

查看:54
本文介绍了键入时搜索栏从视图中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ViewDidLoad()中的 TableView 中添加了 SearchBar :

    self.searchBar = UISearchController(searchResultsController: nil)
    self.searchBar.searchResultsUpdater = self

    self.searchBar.dimsBackgroundDuringPresentation = false
    self.searchBar.searchBar.sizeToFit()

    self.tableView.tableHeaderView = self.searchBar.searchBar
    self.tableView.reloadData()

一切正常,但是当我点击此 SearchBar 时,它消失了.这意味着,我仍然可以键入,并且可以看到结果,但是看不到 SearchBar .我实现了 UISearchBarDelegate ,并且我一直在尝试添加

everything works fine, but when I tap on this SearchBar it disappears. It means, I can still typing, and I can see the results but, don't see SearchBar. I implemented UISearchBarDelegate and I have been trying to add

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    self.navigationController?.navigationBarHidden = false
}

func searchBarTextDidEndEditing(searchBar: UISearchBar) {
    self.navigationController?.navigationBarHidden = true
}

,但仍然无法正常工作.您有什么想法,为什么 Search Bar 消失了?

but it still doesn't work. Do you have any idea, why this Search Bar disappears?

此问题的解决方案是(例如@sandy sad)在 viewDidLoad()

solution of this problem is (like @sandy sad) write this line of code in viewDidLoad()

 self.aNavigationController?.extendedLayoutIncludesOpaqueBars = true

但是现在我有一个新问题,这意味着当我在 TableView 中选择行并显示新的 VievController 时, SearchBar 不会消失并且我在新视图中看到它.为什么?

but now I have a new problem it's mean When I select row in TableView and display new VievController, SearchBar doesn't disappear and I see it in new view. Why?

推荐答案

您需要在viewDidLoad()中将extendedLayoutIncludesOpaqueBars设置为true.

You need to set extendedLayoutIncludesOpaqueBars to true in viewDidLoad().

self.aNavigationController?.extendedLayoutIncludesOpaqueBars = true

这篇关于键入时搜索栏从视图中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆