无法让 UISearchBar 范围栏出现在 iPad 上的工具栏(或任何地方)中

发布于 2024-09-02 08:20:14 字数 2507 浏览 9 评论 0原文

这真的让我很不舒服。我看到很多关于将 UISearchBar 放在 UITableView 的顶行中的信息 - 但我将 UISearchBar 放入屏幕顶部的工具栏中(在 iPad 上)。我找不到任何有关如何在 iPad 上使用 UIPopoverController 处理 UISearchBarUISearchDisplayController 的信息。任何有关使用 UIPopoverControllerUISearchDisplayController 的更多信息将不胜感激。请帮忙解决这个问题,因为我已经无计可施了。

使用 IB,我在 iPad 上的 IUView 上放置了一个工具栏。我向工具栏添加了以下内容:搜索栏不是搜索栏和搜索显示)。我将选项设置如下:显示取消按钮、显示范围栏、范围按钮标题为:“Title1”和“Title2”(选择了 Title2 的单选按钮)。选中不透明、清晰上下文和自动调整大小。我将 Search Bar 的委托连接到“文件所有者”,并将其链接到 IBOutlet theSearchBar

在我的 viewWillAppear 中,我有以下内容:

    //Just in case:
    [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]];
    //Just in case (again):
    [theSearchBar setShowsScopeBar:YES];
    //doesn't seem to do anything:
    //[theSearchBar sizeToFit]; 

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self];
    [self setSearchDisplayController:searchDisplayController];
    [searchDisplayController setDelegate:self];
    [searchDisplayController setSearchResultsDataSource:self];
    //again--does not seem to do anything..but people have suggested it:
    [theSearchBar sizeToFit]; 

好的,到目前为止,我认为一切都很好。因此,我将文件所有者 .m 文件设置为:UISearchBarDelegate、UISearchDisplayDelegate 的委托。

我的问题:我尚未实现执行搜索所需的委托,但仍然...当我单击搜索字段时,我不应该看到搜索字段旁边的 scopeBar 吗?只是为了让您知道我确实看到了我输入的字符的日志,因此委托正在工作。

这是我用来检查 IB 是否确实将范围栏 (UISegementedControl) 放入搜索栏中的例程:

for (UIView *v in theSearchBar.subviews) 
{
    if ([v isMemberOfClass:[UISegmentedControl class]]) 
    {             
        // You've got the segmented control!                 
        UISegmentedControl *scope = (UISegmentedControl *)v;
        // Do your thing here...
        NSLog(@"Found Scope: '%@'\n",scope);
        NSLog(@"Scope Segments: '%d'\n",[v numberOfSegments]);
    }
} 

这表明:

[30013:207] Found Scope: '<UISegmentedControl: 0x68a06b0; frame = (0 0; 200 44); opaque = NO; layer = <CALayer: 0x68a0600>>'
[30013:207] Scope Segments: '2'

所以,我知道这 2 个段在那里。我也知道他们不会出现... 我做错了什么?

为什么范围栏不出现?当我在搜索中键入第一个字符时,结果 UIPopoverController 出现,标题为“结果”和“未找到结果”(当然)...但没有范围栏。 (并不是说我期望除了“未找到结果”之外的任何内容。

我想知道范围栏应该出现在哪里......在 UIPopover 的 titleView 中?在搜索区域在哪里?

This is really causing me fits. I see a lot of info on putting a UISearchBar in the top row of a UITableView -- but I am putting the UISearchBar into the Toolbar at the top of my screen (on the iPad). I cannot find ANYTHING regarding how to handle UISearchBar and UISearchDisplayController using a UIPopoverController on the iPad. Any more info about the UISearchDisplayController using a UIPopoverController would be greatly appreciated. Please help with this as I am at my wit's end.

Using IB, I put a toolbar on the IUView on the iPad. I added the following: Search Bar (not Search Bar and Search Display) to the toolbar. I set the options to be as follows: Show Cancel Button, Show Scope Bar, Scope Button Titles are: "Title1" and "Title2" (with Title2's radio button selected). Opaque, Clear Context and Auto Resize are checked. I hooked up the delegate of Search Bar to the "File's Owner" and linked it to IBOutlet theSearchBar.

In my viewWillAppear I have the following:

    //Just in case:
    [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]];
    //Just in case (again):
    [theSearchBar setShowsScopeBar:YES];
    //doesn't seem to do anything:
    //[theSearchBar sizeToFit]; 

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self];
    [self setSearchDisplayController:searchDisplayController];
    [searchDisplayController setDelegate:self];
    [searchDisplayController setSearchResultsDataSource:self];
    //again--does not seem to do anything..but people have suggested it:
    [theSearchBar sizeToFit]; 

Okay, so far, I thought, so good. So, I made the File's Owner .m file to be a delegate for: UISearchBarDelegate, UISearchDisplayDelegate.

My issue: I have yet to implement the delegates necessary to do the search but still... shouldn't I be seeing the scopeBar next to the search field when I click into the search field? Just so you know I DO see the log of the characters I type, so the delegate is working.

Here is a routine I used to check to see if IB really put the Scope Bar (UISegementedControl) in the searchbar:

for (UIView *v in theSearchBar.subviews) 
{
    if ([v isMemberOfClass:[UISegmentedControl class]]) 
    {             
        // You've got the segmented control!                 
        UISegmentedControl *scope = (UISegmentedControl *)v;
        // Do your thing here...
        NSLog(@"Found Scope: '%@'\n",scope);
        NSLog(@"Scope Segments: '%d'\n",[v numberOfSegments]);
    }
} 

This shows:

[30013:207] Found Scope: '<UISegmentedControl: 0x68a06b0; frame = (0 0; 200 44); opaque = NO; layer = <CALayer: 0x68a0600>>'
[30013:207] Scope Segments: '2'

So, I know the 2 segments are there. I also know they are not showing up...
What am i doing wrong?

Why doesn't the Scope Bar appear? A results UIPopoverController appears with the title "Results" and "No results found" (of course) when i type the first character in my search...but no scope bar. (not that i expect anything other than "No Results Found".

I am wondering where the scope bar is supposed to appear...in the titleView of the UIPopover? In the toolbar to the right of the search area? Where?

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

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

发布评论

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

评论(2

我很坚强 2024-09-09 08:20:14
[self.searchDisplayController searchBar] setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]];

这可能有帮助。

[self.searchDisplayController searchBar] setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]];

This Might Help.

回梦 2024-09-09 08:20:14

当嵌入到 UIToolbar 中时,UISearchBar 不会显示其范围,即使在 iOS 7 中也是如此。

您必须构建自己的 UISegment 并将其添加到搜索结果的表视图中,或者构建自己的视图来保存将显示范围的 UISearchBar 。

UISearchBar does not display it's scope when embedded in a UIToolbar, this is true even in iOS 7.

You must build your own UISegment and add it into the table view of the search results or build your own view to hold the UISearchBar that would display scope.

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