无法使UISearchBar范围栏显示在iPad的工具栏(或任何位置)中
这真的让我很不舒服。我看到很多关于将UISearchBar放在UITableView顶行的信息——但我将UISearchBar放在屏幕顶部的工具栏上(在iPad上)。我找不到任何关于如何在iPad上使用无法使UISearchBar范围栏显示在iPad的工具栏(或任何位置)中,ipad,scope,uisearchbar,uitoolbar,uisearchdisplaycontroller,Ipad,Scope,Uisearchbar,Uitoolbar,Uisearchdisplaycontroller,这真的让我很不舒服。我看到很多关于将UISearchBar放在UITableView顶行的信息——但我将UISearchBar放在屏幕顶部的工具栏上(在iPad上)。我找不到任何关于如何在iPad上使用UIPopoverController处理UISearchBar和UISearchDisplayController的信息。如需了解更多有关使用UIPopoverController的UISearchDisplayController的信息,将不胜感激。请帮我做这件事,因为我已经束手无策了 使用I
UIPopoverController处理UISearchBar
和UISearchDisplayController
的信息。如需了解更多有关使用UIPopoverController
的UISearchDisplayController
的信息,将不胜感激。请帮我做这件事,因为我已经束手无策了
使用IB,我在iPad的iView上放了一个工具栏。我在工具栏中添加了以下内容:搜索栏
(不是搜索栏和搜索显示
)。我将选项设置如下:显示取消按钮、显示范围栏、范围按钮标题为:“标题1”和“标题2”(选中标题2的单选按钮)。选中不透明、清除上下文和自动调整大小。我将搜索栏
的代理连接到“文件所有者”并将其链接到IBOutlet搜索栏
在我的视图中将出现
中,我有以下内容:
//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,uisearchdisplayedelegate
我的问题:我尚未实现执行搜索所需的委托,但仍然。。。当我点击搜索字段时,是否应该看到搜索字段旁边的范围栏
?正如您所知,我确实看到了我键入的字符的日志,因此代理正在工作
下面是我用来检查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'
[30013:207]找到范围:“”
[30013:207]范围段:“2”
所以,我知道有两段。我也知道他们不会出现。。。
我做错了什么
为什么范围栏不出现?当我在搜索中键入第一个字符时,会出现一个结果UIPopoverController,标题为“results”和“No results found”(当然),但没有范围栏。(并不是说我期望“没有结果”
我想知道范围栏应该出现在哪里…在UIPopover的标题视图中?在搜索区域右侧的工具栏中?在哪里
[self.searchDisplayController searchBar] setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]];
这可能会有所帮助。UISearchBar在嵌入UIToolbar时不会显示其作用域,即使在iOS 7中也是如此
您必须构建自己的UISegment并将其添加到搜索结果的表视图中,或者构建自己的视图以保存将显示范围的UISearchBar