UISearchDisplayController - how to preload searchResultTableView

前端 未结 8 1212
深忆病人
深忆病人 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:16

    Working solution for iOS 7:

    // When the tableView is hidden, put it back
    - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
        [self.searchDisplayController.searchResultsTableView reloadData];
        controller.searchResultsTableView.hidden = NO;
    
        // Also, remove the dark overlay
        for (UIView *v in [[controller.searchResultsTableView superview] subviews]) {
            // This is somewhat hacky..
            if (v.alpha < 1) {
                [v setHidden:YES];
            }
        }
    }
    
    -(void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView {
        [self.searchDisplayController.searchResultsTableView reloadData];
        if (self.searchDisplayController.active == YES) {
            tableView.hidden = NO;
        }
    }
    
    0 讨论(0)
  • 2020-12-08 11:18

    This works in iOS 8:

    - (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView
    {
      self.searchDisplayController.searchResultsTableView.hidden = NO;
    }
    
    - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
    {
        self.searchDisplayController.searchResultsTableView.hidden = NO;
        [self.searchDisplayController.searchResultsTableView.superview.superview bringSubviewToFront:self.searchDisplayController.searchResultsTableView.superview];
    
        CGRect frame = self.searchDisplayController.searchResultsTableView.frame;
        self.searchDisplayController.searchResultsTableView.frame = CGRectMake(frame.origin.x, 64, frame.size.width, frame.size.height);
    }
    

    However, I did not like this hack and replaced the searchDisplayController by my own implementation (UISearchBar with UITableView).

    0 讨论(0)
提交回复
热议问题