1

I try to add search bar into cell with identifier and the use this method viewForHeaderInSection which it's come up with an error of

The search bar outlet from the UISearchController to the UISearchBar. Outlet cannot be connected to repeating content.

So basically I want to make search bar staying while scrolling the table view. This is my approach to make it work but it doesn't work.

Any suggestion?

asiandudeCom
  • 441
  • 1
  • 5
  • 26

2 Answers2

0

You should create the UISearchController programmatically:

Create the UISearchController, put this code in viewDidLoad() or viewWillAppear()

var searchController: UISearchController = UISearchController(searchResultsController: nil)

Now assign it to headerView of UITableView. Write the below code in viewDidLoad() method

self.tableView.tableHeaderView = searchController.searchBar

Hope this helps!

FreeGor
  • 615
  • 13
  • 26
Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57
0

If u want it to be always visible on top, u can also put the search bar in navigationBar(of navigation Controller) as its titleView.

self.navigationItem.titleView=self.searchController.searchBar;

And to make it fit the screen in all orientations, just add the following :

[self.searchController.searchBar sizeToFit];

Hope that helps :)

Priyanka
  • 442
  • 1
  • 5
  • 13