I currently have a UISearchBar (code below) which works fine however I'm trying to make it so upon scrolling in my UITableView, my UISearchBar does not disappear. One of the things I've read is to embed a searchController into a view controller with the following line of code:
UISearchBar IBOutlet:
viewDidLoad Func:
UISearchBar Code:
Regarding the View Hierarchy, the SearchBar is below the tableView
Let me know if you have any questions. Any response would be greatly appreciated, thanks!
Code Block navigationItem.searchController = yourSearchController
and then to prevent the UISearchBar from hiding, add this line of code: Code Block navigationItem.hidesSearchBarWhenScrolling = false
however it has not worked. I've also read to put the SearchBar above the UITableView in the View Hierarchy, but when I do that and place it below the Navigation Bar, upon scrolling it overlaps the tableView cells. Do I need a SearchController, and if so, how do I implement this? I've spent hours searching the internet for a solution, however, none of them have resolved my issue.UISearchBar IBOutlet:
Code Block @IBOutlet weak var searchBar: UISearchBar!
viewDidLoad Func:
Code Block filteredData = data
UISearchBar Code:
Code Block func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { if searchText.isEmpty { filteredData = data } else { filteredData = data.filter{$0.title.range(of: searchText, options: .caseInsensitive) != nil } } self.tableView.reloadData() } }
Regarding the View Hierarchy, the SearchBar is below the tableView
Let me know if you have any questions. Any response would be greatly appreciated, thanks!