在Xcode5 / iOS7中搜索没有文本的UISearchBar [英] Search a UISearchBar with no text in Xcode5 / iOS7

查看:96
本文介绍了在Xcode5 / iOS7中搜索没有文本的UISearchBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm updating my app for iOS 7 and one of my functions that allowed a search bar search button to be activated with no text in the search bar stopped working. I used the following code. ANy suggestions on how to make it work again? Thanks in advance.

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


推荐答案

在iOS 7中有一个小改动,现在你必须迭代两个级别。

In iOS 7 there is a small change, now you have to iterated two levels.

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

这篇关于在Xcode5 / iOS7中搜索没有文本的UISearchBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆