xcode 您如何获取用户在搜索栏中输入的文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6364455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:16:24  来源:igfitidea点击:

How do you get the text the user entered into the search Bar?

xcodesearchuisearchbarsearchbar

提问by gikygik

I want to be able to get the text the user entered into a search bar, and compare the words in an array. But i'm not sure how to get the text from the search bar, I know in java its just getText.

我希望能够获取用户在搜索栏中输入的文本,并比较数组中的单词。但我不确定如何从搜索栏中获取文本,我知道在 Java 中它只是 getText。

回答by PengOne

Assuming you named the UISearchBarjust searchBar, you can retrieve the text with

假设您命名为UISearchBarjust searchBar,您可以使用

searchBar.text

回答by iAnkit

In SearchBar Delegate method, you can get searchbar text

在 SearchBar Delegate 方法中,您可以获得搜索栏文本

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    NSString *str = searchBar.text;
    NSLog(@"%@",str);
}