UISearchDisplayController - a table that overlaps the search bar

I have a subclass UITableViewControllerdisplayed modally on an iPad. The view controller has a subclass of UISearchDisplayControllerc UISearchBar, included in the table header view.

The subclassian UISearchDisplayControlleris called NoAnimationSearchDisplayController, and I redefined the method - (void)setActive:(BOOL)visible animated:(BOOL)animated to prevent the search bar from being animated in the navigation bar when it is set to active. Overriding the method below ...

- (void)setActive:(BOOL)visible animated:(BOOL)animated
{

    if (self.active == visible) {
        return;
    }

    [self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];

    [super setActive:visible animated:animated];

    [self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];

    if (visible) {
        [self.searchBar becomeFirstResponder];
    } else {
        [self.searchBar resignFirstResponder];
    }

}

The problem I ran into is that when I searched and the results are displayed in my view of the table of the display controller, everything looks fine, until I scroll down the list, at the moment the content appears inside the cells above the search bar, as shown on the next screen:

enter image description here

UISearchBarStyleMinimal, . - , , ? , .

+1
2

, , UIsearchDisplayController ...

- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {

    /**
     *  Remove content inset automatically set by UISearchDisplayController as we are forcing the
     *  search bar to stay in the header view of the table, and not go into the navigation bar.
     */

    [tableView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];


    /**
     *  Recalculate the bounds of our table view to account for the additional 44 pixels taken up by
     *  the search bar, but store this in an iVar to make sure we only adjust the frame once. If we 
     *  don't store it in an iVar it adjusts the frame for every search.
     */

    if (CGRectIsEmpty(_searchTableViewRect)) {

        CGRect tableViewFrame = tableView.frame;

        tableViewFrame.origin.y = tableViewFrame.origin.y + 44;
        tableViewFrame.size.height =  tableViewFrame.size.height - 44;

        _searchTableViewRect = tableViewFrame;

    }

    [tableView setFrame:_searchTableViewRect];

}
+1

, ( /xib ) . , .

+1

Source: https://habr.com/ru/post/1542130/


All Articles