【问题标题】:UISearchBar in UINavigationController with cancel button not selectableUINavigationController 中的 UISearchBar,取消按钮不可选
【发布时间】:2011-10-06 19:39:53
【问题描述】:

我在 UINavigationController 中添加了一个 UISearchBar 就好了,但是一旦我将取消按钮添加到搜索栏,我就无法再通过触摸它来选择它。

我用来创建和添加搜索栏的代码是:

UISearchBar *theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f,0.0f,320.0f,0.0f)];
theSearchBar.delegate = self;
[theSearchBar setPlaceholder:@"Search iPad"];
[theSearchBar setShowsCancelButton:YES animated:YES];
self.navigationItem.titleView = theSearchBar;
self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[theSearchBar release];

如果我删除添加取消按钮的行,我可以专注于搜索栏并且搜索正常工作。只要我把那条线放进去,它就可以正常显示,但我不能再专注于它了。

我尝试将它放入一个简单的 UIView 容器中,但这也没有解决问题。

如果添加取消按钮会导致此操作失败怎么办?

更新: 我最终没有使用取消按钮,因为我确定搜索栏的使用方式没有必要。

【问题讨论】:

    标签: objective-c ios uinavigationcontroller focus uisearchbar


    【解决方案1】:

    我肯定会推荐一个 UISearchDisplayController:apple docs. 它有一个内置的取消按钮,通过将其放置在界面构建器中,您可以节省大量代码。更少的代码 = 更少的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多