@@ -35,16 +35,20 @@ @interface CSSearchDisplayVC () <UISearchBarDelegate, UITableViewDelegate, UITab
3535@property (nonatomic , strong ) NSMutableArray *tweetsArr;
3636@property (nonatomic , assign ) NSInteger totalPage;
3737@property (nonatomic , assign ) NSInteger currentPage;
38+ @property (nonatomic , assign ) NSInteger totalCount;
3839@property (nonatomic , assign ) BOOL isLoading;
40+ @property (nonatomic , strong ) UILabel *headerLabel;
3941
4042@property (nonatomic , strong ) UIScrollView *searchHistoryView;
4143
4244- (void )initSubViewsInContentView ;
4345- (void )initSearchResultsTableView ;
4446- (void )initSearchHistoryView ;
45- - (void )didClickedMoreHotkey : (id )sender ;
47+ - (void )didClickedMoreHotkey : (UIGestureRecognizer * )sender ;
4648- (void )didCLickedCleanSearchHistory : (id )sender ;
4749- (void )didClickedContentView : (UIGestureRecognizer *)sender ;
50+ - (void )didClickedHistory : (UIGestureRecognizer *)sender ;
51+
4852@end
4953
5054@implementation CSSearchDisplayVC
@@ -106,7 +110,7 @@ - (void)setActive:(BOOL)visible animated:(BOOL)animated {
106110
107111 [self initSubViewsInContentView ];
108112 }
109-
113+
110114// [self.searchBar.superview addSubview:_backgroundView];
111115// [self.searchBar.superview addSubview:_contentView];
112116// [self.searchBar.superview bringSubviewToFront:_contentView];
@@ -123,18 +127,19 @@ - (void)setActive:(BOOL)visible animated:(BOOL)animated {
123127
124128- (void )initSubViewsInContentView {
125129
126- UILabel *lblHotKey = [[UILabel alloc ] initWithFrame: CGRectMake (12 .0f , 5 .0f , 100 , 30 .0f )];
130+ UILabel *lblHotKey = [[UILabel alloc ] initWithFrame: CGRectMake (12 .0f , 5 .0f , kScreen_Width , 30 .0f )];
131+ [lblHotKey setUserInteractionEnabled: YES ];
127132 [lblHotKey setText: @" 热门话题" ];
128133 [lblHotKey setFont: [UIFont systemFontOfSize: 14 .0f ]];
129134 [lblHotKey setTextColor: [UIColor colorWithHexString: @" 0x999999" ]];
130135 [_contentView addSubview: lblHotKey];
131136
132- UIImage *imgMore = [UIImage imageNamed: @" me_info_arrow_left " ];
133- _btnMore = [UIButton buttonWithType: UIButtonTypeCustom ];
134- _btnMore = [[UIButton alloc ] initWithFrame: CGRectMake ( kScreen_Width - 31 . 0f , 10 . 0f , 20 . 0f , 20 . 0f )];
135- [_btnMore setImage: imgMore forState: UIControlStateNormal ];
136- [_btnMore addTarget: self action: @selector ( didClickedMoreHotkey: ) forControlEvents: UIControlEventTouchUpInside ];
137- [_contentView addSubview: _btnMore ];
137+ UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector ( didClickedMoreHotkey: ) ];
138+ [lblHotKey addGestureRecognizer: tapGestureRecognizer ];
139+
140+ UIImageView *moreIconView = [[UIImageView alloc ] initWithFrame: CGRectMake ( kScreen_Width - 31 . 0f , 10 . 0f , 20 . 0f , 20 . 0f ) ];
141+ moreIconView. image = [UIImage imageNamed: @" me_info_arrow_left " ];
142+ [_contentView addSubview: moreIconView ];
138143
139144 _topicHotkeyView = [[TopicHotkeyView alloc ] init ];
140145 [_contentView addSubview: _topicHotkeyView];
@@ -173,6 +178,8 @@ - (void)initSearchResultsTableView {
173178
174179 _tweetsArr = [[NSMutableArray alloc ] init ];
175180 _currentPage = 1 ;
181+ _totalCount = 0 ;
182+ _totalPage = 0 ;
176183
177184 if (!_searchTableView) {
178185 _searchTableView = ({
@@ -190,11 +197,25 @@ - (void)initSearchResultsTableView {
190197 }];
191198 }
192199
193- // [self.searchBar.superview addSubview:tableView];
194200 [self .parentVC.parentViewController.view addSubview: tableView];
201+
202+ self.headerLabel = ({
203+
204+ UILabel *label = [[UILabel alloc ] initWithFrame: CGRectMake (0 , 0 , kScreen_Width , 35 )];
205+ label.backgroundColor = [UIColor whiteColor ];
206+ label.textColor = [UIColor colorWithHexString: @" 0x999999" ];
207+ label.textAlignment = NSTextAlignmentCenter;
208+ label.font = [UIFont systemFontOfSize: 12 ];
209+
210+ label;
211+ });
212+
213+ tableView.tableHeaderView = self.headerLabel ;
214+
195215 tableView;
196216 });
197217 }
218+ [_searchTableView.superview bringSubviewToFront: _searchTableView];
198219// [self.searchBar.superview bringSubviewToFront:_searchTableView];
199220
200221 // _refreshControl = [[ODRefreshControl alloc] initInScrollView:self.searchTableView];
@@ -225,25 +246,35 @@ - (void)initSearchHistoryView {
225246
226247 NSArray *array = [CSSearchModel getSearchHistory ];
227248 CGFloat imageLeft = 12 .0f ;
228- CGFloat textLeft = 32 .0f ;
249+ CGFloat textLeft = 34 .0f ;
229250 CGFloat height = 35 .0f ;
230251 UILabel *lblHistory = nil ;
231252 UIImageView *imageView = nil ;
253+ UIImageView *rightImageView = nil ;
232254 UIImage *image = [UIImage imageNamed: @" time_clock_icon" ];
233255
234256 for (int i = 0 ; i < array.count ; i++) {
235257
236- lblHistory = [[UILabel alloc ] initWithFrame: CGRectMake (textLeft, i * height, kScreen_Width - 2 * textLeft, height)];
258+ lblHistory = [[UILabel alloc ] initWithFrame: CGRectMake (textLeft, i * height, kScreen_Width - textLeft, height)];
259+ lblHistory.userInteractionEnabled = YES ;
237260 lblHistory.textColor = [UIColor colorWithHexString: @" 0x999999" ];
238261 lblHistory.text = array[i];
239262
240263 imageView = [[UIImageView alloc ] initWithImage: image];
241264 imageView.frame = CGRectMake (imageLeft, i * height + (35 - image.size .height ) / 2 + 2 , image.size .width , image.size .height );
242265
266+ rightImageView = [[UIImageView alloc ] initWithImage: image];
267+ rightImageView.frame = CGRectMake (kScreen_Width - textLeft, i * height + (35 - image.size .height ) / 2 + 2 , image.size .width , image.size .height );
268+
269+ UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (didClickedHistory: )];
270+ [lblHistory addGestureRecognizer: tapGestureRecognizer];
271+
243272 [_searchHistoryView addSubview: lblHistory];
244273 [_searchHistoryView addSubview: imageView];
274+ [_searchHistoryView addSubview: rightImageView];
245275 lblHistory = nil ;
246276 imageView = nil ;
277+ rightImageView = nil ;
247278 }
248279
249280 if (array.count ) {
@@ -259,7 +290,7 @@ - (void)initSearchHistoryView {
259290
260291}
261292
262- - (void )didClickedMoreHotkey : (id )sender {
293+ - (void )didClickedMoreHotkey : (UIGestureRecognizer * )sender {
263294
264295 RKSwipeBetweenViewControllers *nav_topic = [RKSwipeBetweenViewControllers newSwipeBetweenViewControllers ];
265296 [nav_topic.viewControllerArray addObjectsFromArray: @[[CSHotTopicVC new ],[CSMyTopicVC new ]]];
@@ -276,6 +307,8 @@ - (void)didClickedMoreHotkey:(id)sender {
276307 [self .parentVC presentViewController: nav_topic animated: NO completion: ^{
277308
278309 }];
310+
311+ // [self.parentVC.parentViewController.navigationController pushViewController:nav_topic animated:YES];
279312 }
280313}
281314
@@ -290,6 +323,17 @@ - (void)didClickedContentView:(UIGestureRecognizer *)sender {
290323 [self .searchBar resignFirstResponder ];
291324}
292325
326+ - (void )didClickedHistory : (UIGestureRecognizer *)sender {
327+
328+ UILabel *label = (UILabel *)sender.view ;
329+ self.searchBar .text = label.text ;
330+ [CSSearchModel addSearchHistory: self .searchBar.text];
331+ [self initSearchHistoryView ];
332+ [self .searchBar resignFirstResponder ];
333+
334+ [self initSearchResultsTableView ];
335+ }
336+
293337#pragma mark -
294338#pragma mark Search Data Request
295339
@@ -317,6 +361,9 @@ - (void)requestDataWithPage:(NSInteger)page {
317361 if (page < 1 )
318362 page = 1 ;
319363
364+ if (page == 1 )
365+ self.headerLabel .text = @" " ;
366+
320367 _isLoading = YES ;
321368
322369 __weak typeof (self) weakSelf = self;
@@ -327,6 +374,7 @@ - (void)requestDataWithPage:(NSInteger)page {
327374 NSDictionary *dataDic = (NSDictionary *)data;
328375 weakSelf.currentPage = [[dataDic valueForKey: @" page" ] intValue ];
329376 weakSelf.totalPage = [[dataDic valueForKey: @" totalPage" ] intValue ];
377+ weakSelf.totalCount = [[dataDic valueForKey: @" totalRow" ] intValue ];
330378 NSArray *resultA = [NSObject arrayFromJSON: [dataDic objectForKey: @" list" ] ofObjects: @" Tweet" ];
331379 [weakSelf.tweetsArr addObjectsFromArray: resultA];
332380 [weakSelf.searchTableView reloadData ];
@@ -335,6 +383,7 @@ - (void)requestDataWithPage:(NSInteger)page {
335383 }
336384
337385 weakSelf.isLoading = NO ;
386+ weakSelf.headerLabel .text = [NSString stringWithFormat: @" 共搜索到 %ld 个与\" %@ \" 相关的冒泡" , weakSelf.totalCount, weakSelf.searchBar.text, nil ];
338387 }];
339388}
340389
0 commit comments