编辑开始后关闭 UISearchBar 中的范围栏

发布于 2024-11-25 13:51:02 字数 785 浏览 3 评论 0原文

我有一个 UISearchBar 及其各自的搜索显示控制器,通过 InterfaceBuilder 放置在 xib 文件中。搜索栏在 Interface Builder 中配置,未选中“显示范围栏”。但是,一旦在搜索栏中开始文本输入并显示“搜索覆盖”,UISearchBar 将与范围栏一起显示,该范围栏有 2 个按钮及其默认“标题”。

如何确保开始编辑 SearchBar 时不显示范围栏?

我已经从管理搜索栏的 ViewController 类中尝试过这些:

- (void)viewDidLoad
{    
    UISearchBar *searchBar = self.searchDisplayController.searchBar;
    NSLog(@"Scopebar is visible? %@", searchBar.showsScopeBar == YES ? @"YES" : @"NO");
    searchBar.showsScopeBar = NO; // Doesn't seem to have an effect
}

#pragma mark - UISearchBarDelegate methods
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [searchBar setShowsScopeBar:NO]; // doesn't seem to work either
    return YES;
}

Apple 的示例代码 TableSearch,它说明一旦搜索开始,搜索就会有 4 个按钮范围栏。

I have a UISearchBar and its respective Search Display Controller laid out in xib file via InterfaceBuilder. The search bar is configured in Interface Builder with "Shows Scope Bar" unchecked. However, once text entry starts in the search bar and the 'search overlay' is shown, UISearchBar is shown with the Scope Bar that has 2 buttons and their default "Title".

How do I make sure that the Scope Bar is not shown when SearchBar editing has begun?

I've tried these from my ViewController class that manages the search bar:

- (void)viewDidLoad
{    
    UISearchBar *searchBar = self.searchDisplayController.searchBar;
    NSLog(@"Scopebar is visible? %@", searchBar.showsScopeBar == YES ? @"YES" : @"NO");
    searchBar.showsScopeBar = NO; // Doesn't seem to have an effect
}

#pragma mark - UISearchBarDelegate methods
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [searchBar setShowsScopeBar:NO]; // doesn't seem to work either
    return YES;
}

Apple's sample code, TableSearch, that illustrates search has the 4 button scope bar once search has started.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回首观望 2024-12-02 13:51:02

如果您查看 InterfaceBuilder,您将在“显示范围栏”复选框下方的“范围标题”列表中看到两次“标题”。当您选中复选框时,InterfaceBuilder 会添加它们。当您取消选中时,它不会删除它们,但当您单击正在运行的应用程序中的搜索框时,它们仍然会出现。在 InterfaceBuilder 中,暂时重新启用“显示范围栏”复选框,以允许您选择每个“标题”行,然后单击“-”按钮将其删除。然后取消选中“显示范围栏”。你不应该再看到他们了。

If you look in InterfaceBuilder you will see "Title" twice in the "Scope Titles" list just underneath the "Shows Scope Bar" checkbox. InterfaceBuilder adds them when you check the checkbox. It doesn't remove them when you uncheck, but they will still appear when you click in the Search box in your running app. In InterfaceBuilder, temporarily re-enable the "Shows Scope Bar" checkbox to allow you to select each "Title" row and click the "-" button to remove them. Then un-check "Shows Scope Bar". You shouldn't see them any more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文