UISearchDisplayController - how to preload searchResultTableView

前端 未结 8 1214
深忆病人
深忆病人 2020-12-08 10:56

I want to show some default content when the user taps the Searchbar, but before any text is entered.

I have a solution working using settext:

- (voi         


        
8条回答
  •  再見小時候
    2020-12-08 11:03

    I have the solution. Insert these three methods.You have to have the tableview preloaded with the data in order this to work. I have this codes working in my code so it has to work for you as long as you have already preloaded the data and you are using search display controller.

    - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
    {
        CGRect testFrame = CGRectMake(0, self.notesSearchBar.frame.size.height, self.notesSearchBar.frame.size.width, self.view.frame.size.height - self.notesSearchBar.frame.size.height);
        self.searchDisplayController.searchResultsTableView.frame = testFrame;
        [self.notesSearchBar.superview addSubview:self.searchDisplayController.searchResultsTableView];
    
    //    [self.view addSubview:self.searchDisplayController.searchResultsTableView];
        controller.searchResultsTableView.hidden = NO;
    }
    
    -(void) searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView
    {
        CGRect testFrame = CGRectMake(0, self.notesSearchBar.frame.size.height, self.notesSearchBar.frame.size.width, self.view.frame.size.height - self.notesSearchBar.frame.size.height);
        self.searchDisplayController.searchResultsTableView.frame = testFrame;
        [self.notesSearchBar.superview addSubview:self.searchDisplayController.searchResultsTableView];
    
        //    [self.view addSubview:self.searchDisplayController.searchResultsTableView];
        controller.searchResultsTableView.hidden = NO;
    }
    
    
    -(void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
    {
        controller.searchResultsTableView.hidden = YES;
    }
    

提交回复
热议问题