Start a Project

Implement UISearchController with Custom UIViewController Support in Swift 4.2

UISearchController with Custom UIViewController Support

Sometimes we need to use search suggestions within the same page that will show over the current screen for that we can use UISearchController with one Target Controller, for this follow these steps.

Here we are taking  2 controllers where one controller loads another controller over the screen.

1: Define First Controller:

Create A UIview On controller  & create their outlet.

Now write this code on ViewDidLoad()

Note: here  “TableViewControllerClass” is another UITableViewController class that will load when the user clicks on the search bar.

2: Define the  TableViewControllerClass

Note: ” func updateSearchResults(for searchController: UISearchController)”  this method will call every time when the user clicks on search bar & type on search bar so this method will help to reload the data or update the data in that controller.

Now it will look like this:

 

Exit mobile version