在Xcode5/iOS7中搜索没有文本的UISearchBar

use*_*673 3 uisearchbar ios7

我正在更新我的iOS 7应用程序和我的一个功能,允许激活搜索栏搜索按钮,搜索栏中没有文字停止工作.我使用了以下代码.关于如何让它再次运作的任何建议?提前致谢.

UITextField *searchBarTextField = nil;
for (UIView *subview in self.searchBar.subviews)
{
    if ([subview isKindOfClass:[UITextField class]])
    {
        searchBarTextField = (UITextField *)subview;
        break;
    }
}
searchBarTextField.enablesReturnKeyAutomatically = NO;
Run Code Online (Sandbox Code Playgroud)

Adn*_*tab 6

在iOS 7中有一个小的变化,现在你必须迭代两个级别.

  for (UIView *subView in self.searchBar.subviews){
    for (UIView *secondLeveSubView in subView.subviews){
    if ([secondLeveSubView isKindOfClass:[UITextField class]])
        {
            searchBarTextField = (UITextField *)2ndLeveSubView;
            break;
        }
    }
   }
Run Code Online (Sandbox Code Playgroud)

  • 自 iOS 2.0 起就存在:@property(nonatomic) BOOL enableReturnKeyAutomatically; (2认同)

Car*_*enA 5

搜索栏上直接有 enableReturnKeyAutomatically 选项。

searchbar.enablesReturnKeyAutomatically = NO;
Run Code Online (Sandbox Code Playgroud)