我在 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/