DenTelezhkin / DTTableViewManager

Protocol-oriented UITableView management, powered by generics and associated types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the best way to integrate UISearchDisplayController?

orkenstein opened this issue · comments

Yep, the question is: what is the best way to add filtering using DTTableViewManager?
Thanks in advance.

Hi orkenstein,

since UISearchDisplayController has been deprecated in iOS 8, I suggest you use UISearchController if you don't have to support iOS 7 and lower.

You can just make your own UITableViewController subclass and use it while instantiating the search controller:

resultsTableViewController = ResultsTableViewController() UISearchController(searchResultsController: resultsTableViewController)

In the example resultsTableViewController could be a DTTableViewManageable.

I did that a few days ago and it worked very well.

I agree, you should use UISearchController, there's no real reason to use UISearchDisplayController.

Either way, everything should look similar to what you would do without DTTableViewManager. You should have two datasources - original and filtered. It probably would be easier if those datasources contained [SectionModel].

Then, you can recount filtered datasource when your search term changes, and just call

manager.memoryStorage.sections = filteredSections
tableView.reloadData()

In previous releases of DTTableViewManager i included searching functionality, but then i realized it was very hard to maintain because search logic differs incredibly. You might have network search, or local search. You might have search within CoreData. You might have search that includes sections, and search that works in a single section. It's very hard to support all those variants, which is why it's not included in Core functionality.

If you have CoreData search, there's example included in Example folder. Hope this helps.