我有UIViewController,它採用了UISearchBarDelegate。並將其代理設置爲self:resultSearchController.searchBar.delegate = self。它工作正常,我searchBarCancelButtonClicked方法%Swift:searchBar - 如何更改「取消」按鈕標題
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
println("Сancel button tapped")
}
測試它我看到「Сancel按鈕竊聽」控制檯。但我想改變「取消」按鈕標題,我不知道如何。我試過:
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
var barButton = UIBarButtonItem(title: "Button Title", style: UIBarButtonItemStyle.Done, target: self, action: "here")
self.resultSearchController.searchBar.showsCancelButton = false
self.resultSearchController.navigationItem.rightBarButtonItem = barButton
}
但它不起作用。請問你能幫幫我嗎?
我不使用UISearchDisplayController它已棄用。我使用UISearchController。所以這段代碼不能幫助我。 – user3742622 2015-04-04 16:59:39