我有一个UISearchBar和它各自的搜索显示控制器通过InterfaceBuilder在xib文件中布局.搜索栏在Interface Builder中配置为"显示范围栏"未选中.但是,一旦文本输入在搜索栏中开始并显示"搜索覆盖",UISearchBar就会显示,其中Scope Bar有2个按钮,默认为"Title".
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;
}
Run Code Online (Sandbox Code Playgroud)
Apple的示例代码TableSearch,一旦搜索开始,它就会显示4个按钮范围栏.
我怎么能最初隐藏UITableView的UISearchDisplayController?我只想让用户向上滚动以查看UISearchBar.
更新:我正在考虑将UITableView 40px向下滚动,以便可以从用户"隐藏"UISearchBar.
UITable一个UISearchDisplayController.UITable是小于屏幕的宽度(它是280像素宽度居中).search bar,UISearchDisplayController表格一直到屏幕的左边.UISearchDisplayController,我仍然得到相同的定位.我在这里设置框架:
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView {
tableView.backgroundColor = [UIColor colorWithRed:29.0/255.0 green:30.0/255.0 blue:32.0/255.0 alpha:1];
tableView.rowHeight = self.myTable.rowHeight;
tableView.frame = myTable.frame;
NSLog(@"search table origin: %f",tableView.frame.origin.x);
}
Run Code Online (Sandbox Code Playgroud)
甚至更奇怪的是,当我在最后记录搜索表位置时,它显示16.但是,它在视图中的位置0处.
任何帮助表示赞赏.
我已UISearchDisplayController正确连接到UITableViewIB 中的自定义标题.但是,当我搜索任何内容时,searchResultsTableView只显示"无结果",而我似乎无法找到代码不正确的位置.
searchResults 属性
- (NSMutableArray *)searchResults {
if (!_searchResults) {
_searchResults = [[NSMutableArray alloc] initWithCapacity:self.listingPreviews.count];
}
return _searchResults;
}
Run Code Online (Sandbox Code Playgroud)
表视图数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSInteger numberOfRows = 0;
if (tableView == self.tableView) {
numberOfRows = self.listingPreviews.count;
} else {
numberOfRows = self.searchResults.count;
}
return numberOfRows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Listing";
ListingPreviewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; …Run Code Online (Sandbox Code Playgroud) search objective-c uitableview uisearchdisplaycontroller ios
我有UISearchDisplayController页面视图如下(原始状态)

点击搜索栏并输入一些搜索词后,我会在表格中找到结果列表

单击表中的条目后,将在堆栈顶部显示新的viewController

我的意图是单击取消按钮(左上角),根视图将显示searchDisplay控制器的原始状态

这就是我尝试过的
在我的取消方法中(当我点击左上方的取消按钮时触发)
- (void)cancel
{
[self dismissViewControllerAnimated:YES completion:NULL];
[self searchBarCancelButtonClicked:self.searchDisplayController.searchBar];
}
Run Code Online (Sandbox Code Playgroud)
在searchbar委托方法中我做到了这一点
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
self.searchBar.showsCancelButton = NO;
[self.searchBar resignFirstResponder];
self.searchBar.text = @"";
searchDisplayController.searchResultsTableView.hidden = YES;
[self searchDisplayControllerWillEndSearch:self.searchDisplayController];
}
Run Code Online (Sandbox Code Playgroud)
点击取消按钮后,我设法实现的就是这个

原始的tableview似乎缺失(仅当我点击页面时才会出现)
如何修改我的方法以将搜索恢复到其原始状态?
我有一个基于tabbar的应用程序,以及UInavigationcontroller每个选项卡.在TabViewController,我实现了一个UIsegmentedcontrol,searchDisplayController和UITableView的.navigationItems,tabledata基于segmentedcontrol选择进行更改.对于一个片段,我隐藏了搜索栏.但是当隐藏搜索栏时,tableview第一行不响应didselectrowatindexpath.
这是我的代码,
在细分变更行动中
- (void)indexDidChangeForSegmentedControl:(UISegmentedControl *)aSegmentedControl {
[self changeNavigationItems];
l.text = [NSString stringWithFormat:@"%d",self.segmentControl.selectedSegmentIndex];
if([segmentIndexesToHideSearchBar containsObject: [NSString stringWithFormat:@"%d", self.segmentControl.selectedSegmentIndex]])
{
self.searchDisplayController.searchBar.hidden = YES;
self.dataTable.frame = CGRectMake(0, 0, self.dataTable.frame.size.width, self.dataTable.frame.size.height);
}
else
{
self.searchDisplayController.searchBar.hidden = NO;
self.dataTable.frame = CGRectMake(0, 44, self.dataTable.frame.size.width, self.dataTable.frame.size.height);
}
[self.dataTable reloadData];
Run Code Online (Sandbox Code Playgroud)
}
其他代码是通用的,其他代码正常.
第二个问题是当我通过点击一行从详细信息视图返回时,不保留表格框架的更改.搜索栏有一个空间.
等待帮助.

我想在UISearchbar中添加一个按钮(bar),在UISearchbar外面添加另一个按钮(bar),如图所示.对此有任何帮助表示赞赏.
在此先感谢Naveen
我正在开发一个实现搜索显示控制器的应用程序.搜索结果表视图,一直表现不正常,我试图在几天内解决这个问题.这是一个行为的屏幕录制.

我没有修改表视图的框架或边界.当搜索字段中没有文本并调用该[searchDisplayController setActive: animated: ]方法时,我只是辞职第一响应者.
请帮帮我.
iphone objective-c uitableview uisearchdisplaycontroller ios
我需要在用户点击搜索栏后以模态方式呈现 tableview,然后能够让 tableview 呈现用户搜索的内容,例如 Instagram 的搜索功能。谷歌上有很多关于如何制作搜索功能的教程,但没有关于如何在用户点击搜索栏后呈现表格视图的教程。我该怎么做?
当您进入搜索显示控制器处理的搜索栏时,它会向上滑动视图并向上推导航栏.这很容易做到,但是,当您单击搜索结果并在导航控制器的堆栈上按下新视图时,导航栏将从右侧滑入视图!
这是怎么做到的?如果您只是将导航栏设置为隐藏或显示,则会立即发生.我无法弄清楚它是如何隐藏在堆栈中的一个视图控制器中的!
非常感谢,
迈克尔
iphone uinavigationbar uinavigationcontroller uisearchdisplaycontroller
ios ×7
uitableview ×5
iphone ×4
objective-c ×3
uisearchbar ×3
ios4 ×2
search ×1
swift ×1
swift2 ×1