ios - TableHeaderView 中的搜索栏行为错误

标签 ios swift uitableview uisearchcontroller

我在 tableView 中添加了一个搜索栏,按下时搜索栏就会消失。

这是一个行为错误的 gif:

这是我的简单代码:

import UIKit

class UMSearchBarViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    var searchController : UISearchController!

    override func viewDidLoad() {
        super.viewDidLoad()

        searchController = UISearchController(searchResultsController: nil)

        tableView.tableHeaderView = searchController.searchBar

        // Do any additional setup after loading the view.
    }


}

有什么办法可以解决这个问题吗?

最佳答案

尝试以下代码:在 Swift 3 中测试。

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    // If this is your main controller.try this code inside your viewDidload 
    navigationController?.hidesBarsOnSwipe = false // If you don't want this happend when swipe.
    navigationController?.hidesBarsOnTap = false
}

注意:不要忘记自动约束您的搜索者。

关于ios - TableHeaderView 中的搜索栏行为错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40204467/

相关文章:

ios - 推送后重新加载 UITableViewCell

iphone - JSONRepresentation 显示错误

ios - iTunes 恢复到旧版本

iOS swift : Value of type 'NotificationCenter' has no member 'publisher'

ios - 设备旋转后的 UICollectionView contentOffset

ios - 为什么是: "Attempting to load .. while deallocating... :UISearchController:"

ios - 更改播放视频的 View

ios - Swift - 使用 viewDidAppear 中的新信息重新加载 UIPageViewController

带有 "where Self"子句的 Swift 协议(protocol)

ios - 创建一个静态 TableView ,在一个单元格中有一个分段控件,在另一个单元格中有 3 个 View ,我如何将分段连接到我的 View