Skip to content

Commit cd2b904

Browse files
committed
废弃 QMUITableViewDelegate shouldShowSearchBarInTableView: 方法,使用 QMUICommonTableViewController.shouldShowSearchBar 代替
1 parent 19a1811 commit cd2b904

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

qmuidemo/Modules/Demos/Components/QDEmptyViewController.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ @implementation QDEmptyViewController
1616

1717
- (id)initWithStyle:(UITableViewStyle)style {
1818
if (self = [super initWithStyle:style]) {
19-
19+
self.shouldShowSearchBar = YES;
2020
}
2121
return self;
2222
}
@@ -36,11 +36,7 @@ - (void)reload:(id)sender {
3636
[self.tableView reloadData];
3737
}
3838

39-
#pragma mark - TableView Delegate & DataSource
40-
41-
- (BOOL)shouldShowSearchBarInTableView:(QMUITableView *)tableView {
42-
return YES;
43-
}
39+
#pragma mark - <QMUITableViewDataSource, QMUITableViewDelegate>
4440

4541
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
4642
return self.emptyViewShowing ? 0 : 4;
@@ -81,4 +77,14 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
8177
[self.tableView reloadData];
8278
}
8379

80+
#pragma mark - <QMUISearchControllerDelegate>
81+
82+
- (void)willPresentSearchController:(QMUISearchController *)searchController {
83+
[QMUIHelper renderStatusBarStyleDark];
84+
}
85+
86+
- (void)willDismissSearchController:(QMUISearchController *)searchController {
87+
[QMUIHelper renderStatusBarStyleLight];
88+
}
89+
8490
@end

qmuidemo/Modules/Demos/UIKit/QDObjectViewController.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ @implementation QDObjectViewController
1919

2020
- (instancetype)initWithStyle:(UITableViewStyle)style {
2121
if (self = [super initWithStyle:style]) {
22+
self.shouldShowSearchBar = YES;
23+
2224
self.autocompletionClasses = [[NSMutableArray alloc] init];
2325

2426
dispatch_async(dispatch_get_main_queue(), ^{
@@ -87,10 +89,6 @@ - (double)matchingWeightForResult:(NSString *)className withSearchString:(NSStri
8789

8890
#pragma mark - <QMUITableViewDataSource, QMUITableViewDelegate>
8991

90-
- (BOOL)shouldShowSearchBarInTableView:(QMUITableView *)tableView {
91-
return YES;
92-
}
93-
9492
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
9593
return self.autocompletionClasses.count;
9694
}

qmuidemo/Modules/Demos/UIKit/QDSearchViewController.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ @implementation QDSearchViewController
6969

7070
- (instancetype)initWithStyle:(UITableViewStyle)style {
7171
if (self = [super initWithStyle:style]) {
72+
73+
// 这个属性默认就是 NO,这里依然写出来只是为了提醒 QMUICommonTableViewController 默认就集成了 QMUISearchController,如果你的界面本身就是 QMUICommonTableViewController 的子类,则也可以直接通过将这个属性改为 YES 来创建 QMUISearchController
74+
self.shouldShowSearchBar = NO;
75+
7276
self.keywords = @[@"Helps", @"Maintain", @"Liver", @"Health", @"Function", @"Supports", @"Healthy", @"Fat", @"Metabolism", @"Nuturally"];
7377
self.searchResultsKeywords = [[NSMutableArray alloc] init];
7478
}
@@ -86,11 +90,6 @@ - (void)viewDidLoad {
8690

8791
#pragma mark - <QMUITableViewDataSource,QMUITableViewDelegate>
8892

89-
- (BOOL)shouldShowSearchBarInTableView:(QMUITableView *)tableView {
90-
// 这个方法默认就是返回 NO,这里实现这个 delegate 只是为了说明 QMUICommonTableViewController 默认就集成了 QMUISearchController,如果你的界面本身就是 QMUICommonTableViewController 的子类,则也可以直接通过在这个 delegate 里返回 YES 来使用 QMUISearchController
91-
return NO;
92-
}
93-
9493
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
9594
if (tableView == self.tableView) {
9695
return self.keywords.count;

0 commit comments

Comments
 (0)