@@ -35,6 +35,9 @@ + (void)showATSomeoneWithBlock:(void(^)(NSString *topicName))block{
3535- (void )viewDidLoad {
3636 [super viewDidLoad ];
3737
38+ self.edgesForExtendedLayout = UIRectEdgeNone;
39+ self.automaticallyAdjustsScrollViewInsets = NO ;
40+
3841 _listView = ({
3942 UITableView *tableView = [[UITableView alloc ] initWithFrame: self .view.bounds style: UITableViewStylePlain];
4043 tableView.backgroundColor = [UIColor clearColor ];
@@ -51,6 +54,9 @@ - (void)viewDidLoad {
5154 [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
5255 make.edges .equalTo (self.view );
5356 }];
57+
58+ [tableView setContentInset: UIEdgeInsetsZero];
59+ [tableView setScrollIndicatorInsets: UIEdgeInsetsZero];
5460 tableView;
5561 });
5662 _searchBar = ({
@@ -62,23 +68,11 @@ - (void)viewDidLoad {
6268 [searchBar setTintColor: [UIColor whiteColor ]];
6369 [searchBar insertBGColor: [UIColor colorWithHexString: @" 0x28303b" ]];
6470
65- searchBar.translucent = YES ;
71+ searchBar.translucent = NO ;
6672
6773 searchBar;
6874 });
6975
70- //
71- // UISearchBar *searchBar = [UISearchBar new];
72- // searchBar.showsCancelButton = YES;
73- // [searchBar sizeToFit];
74- // UIView *barWrapper = [[UIView alloc]initWithFrame:searchBar.bounds];
75- // [barWrapper addSubview:searchBar];
76- // self.navigationItem.titleView = barWrapper;
77-
78- // [self.navigationController.view addSubview:_searchBar];
79- // [_searchBar setY:20];
80-
81-
8276 _mySearchDisplayController = ({
8377 UISearchDisplayController *searchVC = [[CSMySearchDisplayController alloc ] initWithSearchBar: _searchBar contentsController: self ];
8478 [searchVC.searchResultsTableView registerClass: [CSTopicNameCell class ] forCellReuseIdentifier: kCellIdentifier_TopicNameCell ];
@@ -89,6 +83,12 @@ - (void)viewDidLoad {
8983// searchVC.displaysSearchBarInNavigationBar = NO;
9084// }
9185 searchVC.displaysSearchBarInNavigationBar = YES ;
86+ [searchVC.searchResultsTableView setContentInset: UIEdgeInsetsZero];
87+ [searchVC.searchResultsTableView setScrollIndicatorInsets: UIEdgeInsetsZero];
88+ searchVC.searchResultsTableView .sectionFooterHeight = 0 ;
89+ searchVC.searchResultsTableView .sectionHeaderHeight = 0 ;
90+ searchVC.searchResultsTableView .tableHeaderView = [[UIView alloc ] initWithFrame: CGRectZero];
91+ searchVC.searchResultsTableView .tableFooterView = [[UIView alloc ] initWithFrame: CGRectZero];
9292 searchVC;
9393 });
9494
@@ -97,9 +97,6 @@ - (void)viewDidLoad {
9797 _historyTopiclist = [CSTopicModel latestUseTopiclist ];
9898 _hotTopiclist = @[];
9999
100- // self.edgesForExtendedLayout = UIRectEdgeNone;
101- // self.mySearchDisplayController.searchResultsTableView.estimatedSectionHeaderHeight = 0;
102- // [self.mySearchDisplayController.searchResultsTableView setContentOffset:CGPointZero animated:NO];
103100 [self .listView reloadData ];
104101 [self refreshHotTopiclist ];
105102}
@@ -173,7 +170,10 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
173170
174171- (NSInteger )numberOfSectionsInTableView : (UITableView *)tableView {
175172 if (tableView == _mySearchDisplayController.searchResultsTableView ) {
176- return 1 ;
173+ if (_createdTopicName && _createdTopicName.length > 0 ) {
174+ return 1 ;
175+ }
176+ return 0 ;
177177 }
178178 return 2 ;
179179}
@@ -199,11 +199,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
199199 if (tableView == _mySearchDisplayController.searchResultsTableView ) {
200200// selectedTopicName = _createdTopiclist[indexPath.row];
201201 selectedTopicName = _createdTopicName;
202- [cell showCreateBtn: YES ];
203-
204- NSLog (@" ----name %@ " ,_createdTopicName);
205-
206- NSLog (@" show cell" );
202+ [cell showCreateBtn: (_createdTopicName && _createdTopicName.length > 0 )];
207203 }else {
208204 [cell showCreateBtn: NO ];
209205 if (indexPath.section == 0 ) {
@@ -212,6 +208,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
212208 selectedTopicName = _hotTopiclist[indexPath.row];
213209 }
214210 }
211+ if (!selectedTopicName) {
212+ selectedTopicName = @" " ;
213+ }
215214 cell.textLabel .text = [NSString stringWithFormat: @" #%@ #" ,selectedTopicName];
216215
217216 return cell;
@@ -232,13 +231,14 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
232231 }
233232 }
234233
235- if (selectedTopicName) {
236- [self didSelectByTopicName: selectedTopicName];
237- }
238-
234+ [self didSelectByTopicName: selectedTopicName];
239235}
240236
241237- (void )didSelectByTopicName : (NSString *)topicName {
238+ if (!topicName || topicName.length == 0 ) {
239+ return ;
240+ }
241+
242242 [CSTopicModel addAnotherUseTopic: topicName];
243243
244244 // 为了解决键盘状态混淆的问题
@@ -258,25 +258,55 @@ - (void)didSelectByTopicName:(NSString*)topicName {
258258#pragma mark -
259259
260260#pragma mark UISearchBarDelegate
261+ // - (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView{
262+ // [self.mySearchDisplayController.searchResultsTableView reloadData];
263+ // NSLog(@"--willHideSearchResultsTableView--");
264+ // }
265+ //
266+ // - (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
267+ // [self.mySearchDisplayController.searchResultsTableView reloadData];
268+ // NSLog(@"--didShowSearchResultsTableView--");
269+ // }
261270
262271- (void )searchDisplayController : (UISearchDisplayController *)controller willShowSearchResultsTableView : (UITableView *)tableView {
263272 // 解决UISearchDisplayController 顶部的空白区域的问题
264273 [tableView setContentInset: UIEdgeInsetsZero];
265274 [tableView setScrollIndicatorInsets: UIEdgeInsetsZero];
266275}
267276
277+ - (void )searchBarTextDidBeginEditing : (UISearchBar *)searchBar {
278+ [_mySearchDisplayController.searchResultsTableView reloadData ];
279+
280+ }
281+
282+
268283// 解决不显示cancel按钮的问题
269284- (void )searchDisplayControllerWillBeginSearch : (UISearchDisplayController *)controller {
270285 [_mySearchDisplayController setActive: YES animated: YES ];
271286 [_mySearchDisplayController.searchBar setShowsCancelButton: YES animated: YES ];
287+
288+ // self.mySearchDisplayController.searchResultsTableView.hidden = NO;
289+ // _mySearchDisplayController.
290+ // [_mySearchDisplayController.searchResultsTableView reloadData];
291+
292+ // self.navigationController.navigationBar.translucent = YES;
272293}
294+
273295- (void )searchDisplayControllerWillEndSearch : (UISearchDisplayController *)controller {
274296 [_mySearchDisplayController setActive: NO animated: YES ];
275297 [_mySearchDisplayController.searchBar setShowsCancelButton: YES animated: YES ];
298+
299+ // self.mySearchDisplayController.searchResultsTableView.hidden = YES;
300+ // self.navigationController.navigationBar.translucent = NO;
276301}
277302
303+
304+
278305- (void )searchBar : (UISearchBar *)searchBar textDidChange : (NSString *)searchText {
279- [self createTopicWithStr: searchText];
306+ NSString *strippedStr = [searchBar.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet ]];
307+ // [self.createdTopiclist addObject:strippedStr];
308+ _createdTopicName = strippedStr;
309+ [self .mySearchDisplayController.searchResultsTableView reloadData ];
280310}
281311
282312- (void )searchBarCancelButtonClicked : (UISearchBar *)searchBar {
@@ -296,13 +326,6 @@ - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
296326
297327}
298328
299- - (void )createTopicWithStr : (NSString *)searchString {
300- NSString *strippedStr = [searchString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet ]];
301- // [self.createdTopiclist addObject:strippedStr];
302- _createdTopicName = strippedStr;
303- [self .mySearchDisplayController.searchResultsTableView reloadData ];
304- }
305-
306329@end
307330
308331
@@ -347,13 +370,26 @@ - (void)showCreateBtn:(BOOL)showCreateBtn {
347370
348371@implementation CSMySearchDisplayController
349372
350- // - (void)setActive:(BOOL)visible animated:(BOOL)animated
351- // {
352- // [super setActive: visible animated: animated];
373+ - (void )setActive : (BOOL )visible animated : (BOOL )animated
374+ {
375+ [super setActive: visible animated: animated];
376+
377+ // [self.navigationController setNavigationBarHidden:NO animated:NO];
378+ [self .searchContentsController.navigationController setNavigationBarHidden: NO animated: NO ];
379+ //
380+ // CGRect frame = self.searchResultsTableView.frame;
381+ // frame.origin.y = CGRectGetHeight(self.searchContentsController.navigationController.navigationBar.frame);
353382//
354- // [self.searchContentsController.navigationController setNavigationBarHidden:visible animated: NO];
355- // }
356-
383+ // frame.size.height = CGRectGetHeight(frame) - CGRectGetMinY(frame);
384+ //
385+ // self.searchResultsTableView.frame = frame;
386+ //
387+ // frame = self.searchBar.frame;
388+ // self.searchBar.frame = frame;
389+
390+ // [self.searchContentsController.view insertSubview:self.searchBar aboveSubview:self.searchResultsTableView];
391+
392+ }
357393
358394
359395@end
0 commit comments