UISearchDisplayController masquer la searchBar après la search

J'utilise UISearchDisplayController pour chercher dans ma list. Mais quand je search un personnage, il cache searchBar . Voici l'instantané avant que je commence à chercher:

entrez la description de l'image ici

Ici, il cache searchBar comme ceci:

entrez la description de l'image ici

 #pragma mark - UISearchDisplayController Delegate Methods //These methods will be used for search controller frame - (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil]; } - (void) keyboardWillHide { UITableView *tableView = [[self searchDisplayController] searchResultsTableView]; [tableView setContentInset:UIEdgeInsetsZero]; [tableView setScrollIndicatorInsets:UIEdgeInsetsZero]; } - (void) searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchSsortingng:(NSSsortingng *)searchSsortingng { dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.001); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ for (UIView* v in self.searchDisplayController.searchResultsTableView.subviews) { if ([v isKindOfClass: [UILabel class]] && [[(UILabel*)v text] isEqualToSsortingng:@"No Results"]) { [(UILabel *)v setText:NO_RESULT_LABEL_STRING]; // .. do whatever you like to the UILabel here .. break; } } }); [self handleSearchForTerm:searchSsortingng]; return YES; } - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { [[self dealsTableView] reloadData]; } #pragma mark Search Method - (void) handleSearchForTerm:(NSSsortingng *) searchSsortingng { //First get all the objects which fulfill the criteria [[self searchResultsArray] removeAllObjects]; for (Deal *currentDeal in self.dealsArray) { NSArray *searchQueryComponents = [searchSsortingng componentsSeparatedBySsortingng:@" "]; BOOL isGoAheadToAdd=YES; for (NSSsortingng *currentSearchComponent in searchQueryComponents) { NSSsortingng *sortingmmed = [currentSearchComponent ssortingngByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; if ([sortingmmed length]>0) { if ([[currentDeal title] rangeOfSsortingng:currentSearchComponent options:NSCaseInsensitiveSearch].location != NSNotFound) { isGoAheadToAdd=YES; } else { isGoAheadToAdd=NO; break; } } } if (isGoAheadToAdd) { [[self searchResultsArray] addObject:currentDeal]; } } } 

essaye ça

 @interface MySearchDisplayController : UISearchDisplayController @end @implementation MySearchDisplayController - (void)setActive:(BOOL)visible animated:(BOOL)animated { [super setActive: visible animated: animated]; [self.searchContentsController.navigationController setNavigationBarHidden: NO animated: NO]; } 

J'ai dû définir le cadre pour searchResultsTableView parce que son origine était à (0,0).

Résolu par ceci:

 -(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { [tableView setFrame:CGRectMake(0, 42, 320, 380)]; } 

Par défaut, UISearchDisplayController définit le cadre de searchResultsTableView à (0,0), de sorte que searchBar se cache derrière searchResultsTableView .