2016-09-22 65 views
0
let searchController = UISearchController(searchResultsController: nil) 
uiView.addSubview(searchController.searchBar) 
    searchController.searchResultsUpdater = self 
    searchController.dimsBackgroundDuringPresentation = false 
    definesPresentationContext = true 

如何將動作添加到搜索欄的取消按鈕。一旦用戶按下取消按鈕,我想重新加載表格的數據。在uisearchController中設置取消按鈕的動作

回答

0

您需要設置UISearchController的代表,像這樣:

searchController.searchBar.delegate = self; 

然後你就可以將以下方法添加到您的代碼(當取消按鈕被觸發時按下):

func searchBarCancelButtonClicked(searchBar: UISearchBar) { 
} 
+0

當我設置searchController.searchBar.delegate = self。不能指定'searchFilterController'類型的值來鍵入'UISearchBarDelegate' – henry

+0

你是否已將UISearchBarDelegate添加到ViewController標題中,比如'class ViewController:UIViewController,UISearchBarDelegate'? –

相關問題