在现有的tableview中使用objective-C实现UISearchController

时间:2017-08-18 21:18:30

标签: ios objective-c uitableview uisearchcontroller

我有一个基于Objective-C的现有代码,其中有一个视图控制器具有各种UItextFileds(一种注册表单)。从其中1个字段中,加载了一个具有UITableView的新viewcontroller。此视图控制器还有搜索框以显示搜索结果,该搜索结果目前使用" searchDisplayController"实现。

我想使用" UISearchController"来改变实现,我必须使用现有的TableView(已经以编程方式创建)并在其上实现UISearchcontoller。请提供一些好的示例/代码来做到这一点。

我在博客中获得了很多例子,但是所有的例子都是使用swift或创建自己的TableViewContoller。

1 个答案:

答案 0 :(得分:2)

在viewDidLoad中:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
// To have the search bar appear at the top of the tableView
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;