IOS8 UISearchController update UITableView

I have implemented 1UISearchController1 for my tableview, with scopes and everything else. However, it does not display correctly when the view is loaded initially.

I see four different things depending on my actions.

This is what I see when the view opens. I would not expect a scope to appear:

Now if I click on the search bar I see the following:

Then, if I click the Cancel button again, I see this in the table view:

Finally, if I click on the search bar again, I see what I would expect when I first clicked on the search bar:

And if I undo one more time, now the search bar appears correctly as a table:

Here is 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()
    }

      

+3


source to share


2 answers


I understood that. When I removed this line:

self.resultSearchController.searchBar.showsScopeBar = true

      



But left on the line defining the name of the area, he corrected it.

+2


source


I had the same problem and it only seems to have happened in iOS8. In iOS9, the search bar did not cover the table.

I am not using the visibility bar, so the proposed fix does not apply to me.

When adding a line



[self.searchController.searchBar sizeToFit];

      

before assigning the searchBar to the tableview, it worked fine in both iOS8 and iOS9 for me.

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.searchBar.delegate = self;
    self.definesPresentationContext = YES;
    [self.searchController.searchBar sizeToFit];
    self.tableView.tableHeaderView = self.searchController.searchBar;
}

      

-1


source







All Articles