2017-02-13 63 views
0

我該如何去編程地將搜索欄添加到uitableview頭?具體來說,我有一個酒吧按鈕項目,當它被按下時,我想在搜索欄中將動畫顯示到表格視圖標題中,當按下取消按鈕時,它將動畫返回到視圖外,並且標題縮回到正常。這可能嗎?謝謝。如何以編程方式將搜索欄添加到UITableView標頭?

回答

2

它基於斯威夫特2但是這不是很diff來迅速3

添加搜索委託視圖控制器:

UISearchResultsUpdating 

進行搜索:

let searchController = UISearchController(searchResultsController: nil) 

設置此searchController的默認值:

searchController.searchResultsUpdater = self 
searchController.dimsBackgroundDuringPresentation = false 
definesPresentationContext = true 

添加搜索到表:

table.tableHeaderView = searchController.searchBar 

此委託讓你知道開始搜索:

func updateSearchResultsForSearchController(searchController: UISearchController) { 
    filterContentForSearchText(searchController.searchBar.text!) 
} 

Impliment搜索功能:

func filterContentForSearchText(searchText: String, scope: String = "All") { 
    // do some stuff 
} 
相關問題