Closed Goallying closed 3 years ago
(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor];
self.keywords = @[@"Helps", @"Maintain", @"Liver", @"Health", @"Function", @"Supports", @"Healthy", @"Fat", @"Metabolism", @"Nuturally"]; self.searchResultsKeywords = [[NSMutableArray alloc] init];
// self.edgesForExtendedLayout = UIRectEdgeTop ;
[self.view addSubview:self.tableView]; self.mySearchController = [[QMUISearchController alloc] initWithContentsViewController:self]; self.mySearchController.searchResultsDelegate = self;
// self.mySearchController.launchView = [[QDRecentSearchView alloc] init];// launchView 会自动布局,无需处理 frame self.mySearchController.searchBar.qmui_usedAsTableHeaderView = YES;// 以 tableHeaderView 的方式使用 searchBar 的话,将其置为 YES,以辅助兼容一些系统 bug self.tableView.tableHeaderView = self.mySearchController.searchBar;
[self.mySearchController.tableView registerNib:[UINib nibWithNibName:@"PatientCell" bundle:nil] forCellReuseIdentifier:@"idr"];
}
(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath { return 108 ; }
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (self.mySearchController.active) { return self.searchResultsKeywords.count; } return self.keywords.count ; }
(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath { PatientCell cell = [tableView dequeueReusableCellWithIdentifier:@"idr" forIndexPath:indexPath]; if (self.mySearchController.active) { cell.namelb.text = self.searchResultsKeywords[indexPath.row]; }else { cell.namelb.text = self.keywords[indexPath.row]; } return cell ; }
(void)searchController:(QMUISearchController )searchController updateResultsForSearchString:(NSString )searchString {
[self.searchResultsKeywords removeAllObjects];
for (NSString *keyword in self.keywords) { if ([keyword containsString:searchString]) { [self.searchResultsKeywords addObject:keyword]; } }
[searchController.tableView reloadData];
if (self.searchResultsKeywords.count == 0) { [searchController showEmptyViewWithText:@"没有匹配结果" detailText:nil buttonTitle:nil buttonAction:NULL]; } else { [searchController hideEmptyView]; } }
(UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc]initWithFrame:self.view.bounds]; _tableView.delegate = self ; _tableView.dataSource = self ; [_tableView registerNib:[UINib nibWithNibName:@"PatientCell" bundle:nil] forCellReuseIdentifier:@"idr"];
} return _tableView ; }
610 610
我看到了那个回答 但是我没有设置我edgesForExtendedLayout 。
iOS 14 系统
(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor];
self.keywords = @[@"Helps", @"Maintain", @"Liver", @"Health", @"Function", @"Supports", @"Healthy", @"Fat", @"Metabolism", @"Nuturally"]; self.searchResultsKeywords = [[NSMutableArray alloc] init];
// self.edgesForExtendedLayout = UIRectEdgeTop ;
// self.mySearchController.launchView = [[QDRecentSearchView alloc] init];// launchView 会自动布局,无需处理 frame self.mySearchController.searchBar.qmui_usedAsTableHeaderView = YES;// 以 tableHeaderView 的方式使用 searchBar 的话,将其置为 YES,以辅助兼容一些系统 bug self.tableView.tableHeaderView = self.mySearchController.searchBar;
}
(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath { return 108 ; }
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (self.mySearchController.active) { return self.searchResultsKeywords.count; } return self.keywords.count ; }
(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath { PatientCell cell = [tableView dequeueReusableCellWithIdentifier:@"idr" forIndexPath:indexPath]; if (self.mySearchController.active) { cell.namelb.text = self.searchResultsKeywords[indexPath.row]; }else { cell.namelb.text = self.keywords[indexPath.row]; } return cell ; }
(void)searchController:(QMUISearchController )searchController updateResultsForSearchString:(NSString )searchString {
[self.searchResultsKeywords removeAllObjects];
for (NSString *keyword in self.keywords) { if ([keyword containsString:searchString]) { [self.searchResultsKeywords addObject:keyword]; } }
[searchController.tableView reloadData];
if (self.searchResultsKeywords.count == 0) { [searchController showEmptyViewWithText:@"没有匹配结果" detailText:nil buttonTitle:nil buttonAction:NULL]; } else { [searchController hideEmptyView]; } }
(UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc]initWithFrame:self.view.bounds]; _tableView.delegate = self ; _tableView.dataSource = self ; [_tableView registerNib:[UINib nibWithNibName:@"PatientCell" bundle:nil] forCellReuseIdentifier:@"idr"];
} return _tableView ; }