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
How do you get the text the user entered into the search Bar?
提问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 UISearchBar
just searchBar
, you can retrieve the text with
假设您命名为UISearchBar
just 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);
}