UISearchController in Objective-C

suggest change

DarkBlue is not a UIKit color, and tapGestureRecognizer is not declared in this snippet. The first content offset runs before the search bar is the table header, so the bar’s height can still be zero and it is not hidden. Set definesPresentationContext to YES on the controller that should contain the search. This sample filters when the search button is tapped, not through UISearchResultsUpdating.

// Adopt UISearchBarDelegate and UISearchControllerDelegate.

@property (strong, nonatomic)  UISearchController *searchController;

- (void)searchBarConfiguration
{
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchBar.delegate = self;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    
    // Hides search bar initially.  When the user pulls down on the list, the search bar is revealed.
    [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height)];
    
    self.searchController.searchBar.backgroundColor = [UIColor DarkBlue];
    self.searchController.searchBar.tintColor = [UIColor DarkBlue];
    
    self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(_searchController.searchBar.frame));
    self.tableView.tableHeaderView = _searchController.searchBar;
    _searchController.searchBar.delegate = self;
    _searchController.searchBar.showsCancelButton = YES;
    self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetSearchbarAndTableView)];
    [self.view addGestureRecognizer:self.tapGestureRecognizer];
    
}

- (void)resetSearchbarAndTableView{
// Reload your tableview and resign keyboard.
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
// Search cancelled
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
// Implement filtration of your data as per your need using NSPredicate or else.
// then reload your data control like Tableview.
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents