I've implemented a 1UISearchController1 for my tableview, with scopes and everything. However it doesn't display correctly when the view loads initially.
There are four different things I see depending on my actions.
This is what I see when the view first appears. I wouldn't expect the scope bar to appear:

Now, if I click on the search bar, I see this:

Next, if I click on the Cancel button again, I see this on the table view:

Finally, if I tap on the search bar again, I see what I would expect when I tapped on the search bar the first time:

And if I cancel one more time, now the search bar displays correctly on the table view:

Here's the relevant part of my TableViewController.
class BaseWineTableViewController: UITableViewController, UITableViewDelegate, UINavigationControllerDelegate, UITableViewDataSource, UISearchResultsUpdating, UISearchBarDelegate, UISearchControllerDelegate {
var resultSearchController = UISearchController()
func ConfigureSearchController() {
self.resultSearchController = UISearchController(searchResultsController: nil)
self.resultSearchController.searchResultsUpdater = self
self.resultSearchController.searchBar.delegate = self
self.resultSearchController.delegate = self
self.resultSearchController.searchBar.showsCancelButton = true
self.resultSearchController.searchBar.autocapitalizationType = .None
self.resultSearchController.searchBar.showsScopeBar = true
self.resultSearchController.searchBar.scopeButtonTitles = ["All", CELLAR_STATUSES.Cellared, CELLAR_STATUSES.Wishlist, CELLAR_STATUSES.Finished]
self.resultSearchController.definesPresentationContext = true
self.resultSearchController.dimsBackgroundDuringPresentation = false
self.tableView.tableHeaderView = resultSearchController.searchBar
}
override func viewDidLoad() {
super.viewDidLoad()
ConfigureSearchController()
}
I figured it out. When I removed this line:
self.resultSearchController.searchBar.showsScopeBar = true
But left in the line that defines the scope titles, it fixed it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With