2016-10-23 47 views
0

我在我的tableView中添加了一個搜索欄,搜索欄在按下時消失。TableHeaderView中的搜索欄錯誤行爲

這裏是錯誤的行爲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. 
    } 


} 

任何想法來解決這個問題?

+0

試試這行'self.navigationController?.hidesBarsOnSwipe = false'。 – Adeel

回答

0

試試這個代碼:經測試,在斯威夫特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 
} 

不要忘了自動限制您的搜索。