编辑开始后关闭 UISearchBar 中的范围栏
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 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.