【问题标题】:How do you get the text the user entered into the search Bar?您如何获取用户在搜索栏中输入的文本?
【发布时间】:2011-06-15 21:12:53
【问题描述】:

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

【问题讨论】:

    标签: xcode search uisearchbar searchbar


    【解决方案1】:

    假设您将 UISearchBar 命名为 searchBar,您可以使用以下命令检索文本

    searchBar.text
    

    【讨论】:

    • willRotateToInterfaceOrientation:duration: 中对我不起作用。那里是空的。您在哪里可以检索此值?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2021-03-23
      • 1970-01-01
      • 2021-10-21
      • 2018-11-27
      相关资源
      最近更新 更多