标签: uisearchcontroller

如何在 UISearchController 中使用自定义视图控制器来获取结果?

我目前正在尝试为应用程序实现搜索功能。目标是在不同的视图控制器中显示搜索结果。我的意思确切地说是这样的:

UISearchController(searchResultsController: myCustomViewControllerHere)

我在教程中找到的所有答案都使用当前视图控制器和数据作为显示结果的视图控制器,如下所示:

UISearchController(searchResultsController: nil)

有人可以帮忙解决如何做到这一点吗?我链接了一个教程,它显示了同一 VC 上的结果

教程链接

iphone search ios swift uisearchcontroller

3
推荐指数
1
解决办法
3298
查看次数

在iOS 8上使用swift设置占位符文本颜色/隐藏取消按钮

我的导航栏中有一个UiSearchbar.SearchBar风格很小.我在iOS 8上,使用SearchController(没有SearchDisplayController)和Swift.

  1. 我想将占位符和图标颜色设置为白色.这可能吗?到目前为止我发现的所有内容似乎都已过时,或者作者不确定此代码是否会被Apple批准.

  2. 我想摆脱取消按钮,但当我尝试这个: searchController.searchBar.showsCancelButton = false 在viewDidLoad中,取消按钮仍然显示.

我必须说,我正在以编程方式创建searchBar ..

uisearchbar ios swift uisearchcontroller

2
推荐指数
1
解决办法
3356
查看次数

使用没有故事板的UISearchController

我相对较新的iOS(100小时左右),我正在尝试实现一个没有故事板的UISearchController.是否可以通过编程方式执行此操作?

uitableview ios uisearchcontroller

2
推荐指数
1
解决办法
3955
查看次数

使用UITableView实现UISearchController

只是想知道用于Raywenderlich教程的代码如何添加UISearchController和如何使用它UITableViewController我似乎无法让它工作,有人告诉我它可能已经在iOS 8.0中被弃用,有没有人知道关于如何仍然这样做?

UISearchController始建于UIViewControllerNOT脚本!

xcode uitableview swift uisearchcontroller

2
推荐指数
1
解决办法
1794
查看次数

Swift:在Auto Focus中创建的搜索栏

我通过单击按钮创建一个表格视图和一个搜索栏.但我需要搜索栏显示在Auto Focus(用户立即输入文本而不需要在搜索栏内单击).我怎样才能做到这一点 ?

search autofocus swift uisearchcontroller

2
推荐指数
1
解决办法
3697
查看次数

UISearchController-如何从过滤表中选择结果

我正在努力将搜索栏添加到现有应用中。

我有一个表格,其中填充了从服务器下载的数据,并且正在使用新的UISearchController。

我现在使搜索栏全部正常工作,并且随着用户在搜索栏中键入内容,将显示一个经过过滤的新结果表。

我的问题是如何处理用户从这个新的过滤后的搜索结果表中选择一个项目?

我从过滤后的表中添加了一个新的序列,并添加了didSelectRowAtIndexPath,它的工作原理很好-但是当用户从过滤后的表中选择一个项目时,搜索栏仍然存在,然后单击“取消”会使该应用程序崩溃。

因此,我不确定应该怎么做以及如何处理用户从过滤表中选择项目的问题?

我会保持事物的样子,但添加一些代码以在用户选择项目时取消搜索栏吗?

还是我做错了,有没有办法在用户选择过滤项时将选择从过滤表移回主ViewController表?

一如既往地非常感谢您的协助!

ios uisearchcontroller

2
推荐指数
2
解决办法
1660
查看次数

使用UISearchController推送的第二个View Controller不会在UINavigationBar中接收到触摸

我修改AAPLSearchBarEmbeddedInNavigationBarViewController了Apple的UICatalog示例代码,以便AAPLSearchBarEmbeddedInNavigationBarViewController在选择单元格时将其他实例推送到导航堆栈.在第二个视图控制器中,UISearchBar设置为UINavigationBar的标题视图(就像第一个一样)是不可点击的(与第一个不同).这似乎是一个错误.我如何解决它?这是我修改的UICatalog代码:https: //github.com/stevemoser/UICatalog

我也用Xcode 6和7进行了测试.两者都打破了.

uinavigationbar ios uisearchcontroller

2
推荐指数
1
解决办法
215
查看次数

UISearchController不要将viewcontroller推到UISearchController的下方

自动呈现UISearchController和自己呈现搜索控制器之间的行为有所不同。

@implementation MyViewComtroller

// click search barbutton on right of navigationBar
- (void)searchAction:(id)sender {
    ArticleSearchViewController *searchResultsController = [[ArticleSearchViewController alloc] init];
    UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    searchController.searchResultsUpdater = searchResultsController;
    searchController.searchBar.delegate = searchResultsController;
    searchController.delegate = searchResultsController;
    searchController.hidesNavigationBarDuringPresentation = NO;
    [self presentViewController:searchController animated:YES completion:nil];
}

@end

@implementation ArticleSearchViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ArticleDetailController * articleDetailController = [ArticleDetailController new];
   [(UINavigationController *)self.presentingViewController pushViewController:articleDetailController animated:YES];
}

@end
Run Code Online (Sandbox Code Playgroud)

推送操作发生在UISearchController下面。

uinavigationbar uinavigationcontroller uisearchbar ios uisearchcontroller

2
推荐指数
1
解决办法
1008
查看次数

iOS 11中的SearchController无法触及任何tableView单元格

搜索控制器的系统行为:

  • 转到iPhone设置
  • 滑动以显示searchBar
  • 点按searchBar
  • TableView现在有灰色,如果我触摸任何地方(不在searchBar中),searchBar将隐藏
  • 我输入任何文本,tableView现在有正常颜色,我可以点击进入任何搜索过的单元格.

在我的应用程序中,点击任何文本后,tableView仍然是灰色的.我无法点击任何搜索过的单元格.不同之处在于,当我搜索时,我使用updateSearchResultsForSearchController和reloadData 更新旧的tableView(搜索后我没有不同的tableView).

问题是如何在searchcontroller中输入任何文本后隐藏这个灰色视图并有机会点击单元格?

我创建搜索控制器的方式:

UISearchController * search = [[UISearchController alloc] initWithSearchResultsController:nil];
search.searchResultsUpdater = self;
self.navigationItem.searchController = search;
self.navigationItem.hidesSearchBarWhenScrolling = YES;
self.navigationItem.searchController.searchBar.barTintColor = [UIColor blueColor];
self.navigationItem.searchController.searchBar.delegate = self;
Run Code Online (Sandbox Code Playgroud)

以及我如何更新tableView单元格:

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
    self.actualSearchController = searchController;
    self.filteredData = [self filterContentForSearchText:searchController.searchBar.text];
    [self.tableView reloadData];
}

- (NSMutableArray<MySectionContainter *> *)filterContentForSearchText:(NSString *)text {
    NSMutableArray<MySectionContainter *> *sections = [NSMutableArray array];

    for (MySectionContainter *section in self.tableData) {
        NSArray *objects = [sectionInfo.rowObjects filteredArrayUsingPredicate:[self.filterSource predicateForSearching:text]];

        if ([objects count] > 0) { …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios uisearchcontroller

2
推荐指数
1
解决办法
636
查看次数

iOS 13:关闭导航项上的UISearchController会导致tintColor恢复为默认值

我在导航项目上使用UISearchController(导航栏已设置为使用barTintColor和tintColor)。关闭搜索控制器后(点击搜索栏的“取消”按钮),后退按钮的tintColor将恢复为默认值(蓝色)。

屏幕截图1:导航栏的tintColor是 .white 在此处输入图片说明

屏幕截图2:当UISearchController处于活动状态时: 在此处输入图片说明

屏幕快照3:关闭UISearchController时(通过点击“取消”),您会看到“后退”按钮的tintColor恢复为默认值(蓝色),而不是白色: 在此处输入图片说明

屏幕截图上的代码是:


/// View controller is embedded in a UINavigationController, the root view controller of the startup storyboard.
class ViewController: UIViewController {

  lazy var searchController: UISearchController = {
    let controller = UISearchController(searchResultsController: nil)
    controller.searchBar.tintColor = .white
    return controller
  }()

  override func viewDidLoad() {
    super.viewDidLoad()
    if let navigationBar = navigationController?.navigationBar {
      setupNavigationBar(navigationBar)
    }
    if #available(iOS 11.0, *) {
      navigationItem.searchController = searchController
    } else {
      navigationItem.titleView = searchController.searchBar
    }
  }

  func setupNavigationBar(
    _ navigationBar: UINavigationBar,
    barTintColor: UIColor = …
Run Code Online (Sandbox Code Playgroud)

tintcolor uisearchcontroller ios13

2
推荐指数
1
解决办法
149
查看次数