2

我 Swift,我使用UISearcheControllerUISearcheResultUpdating

我用func updateSearchResultsForSearchController

if self.searchController?.searchBar.text.lengthOfBytesUsingEncoding(NSUTF32StringEncoding) > 0 {  
        let searchBarText = self.searchController!.searchBar.text
        var arrResult = DFManager.GetResult(searchBarText)
        self.results?.addObjectsFromArray(arrResult)            
        // Reload a table with results.
        self.searchResultsController?.tableView.reloadData()
    }

但这是结果总是在我逐个字符输入时更新,它使这个应用程序运行缓慢。我希望这个结果只在输入返回键时更新?

4

1 回答 1

0

尝试这个:

func searchBarSearchButtonClicked(searchBar: UISearchBar) {

        //do something
        searchBar.resignFirstResponder() //hide keyboard

    }

并且不要忘记添加 searchBar 委托:

class SomeViewController: UIViewController, UISearchBarDelegate {

   @IBOutlet weak var searchBar: UISearchBar!

   override func viewDidLoad() {
        searchBar.delegate = self
   }

}
于 2015-02-06T07:30:29.413 回答