| | |
| | | #import "YTHSearchTextField.h" |
| | | #import "searchTableViewCell.h" |
| | | #import "SearchDetailListCell.h" |
| | | #import "SearchCell.h" |
| | | |
| | | #import "XYRDetailViewController.h" |
| | | //#import "GDTNativeAd.h" |
| | |
| | | #import "GDTNativeExpressAdView.h" |
| | | |
| | | #import "SearchTitleView.h" |
| | | #import "SearchNavView.h" |
| | | |
| | | static NSString *indentfly = @"cell"; |
| | | static NSString *indentfly2=@"searchTableViewCellID"; |
| | | |
| | | @interface searchDetailViewController ()<YTHSearchTextFieldDelegate,UITableViewDataSource,UITableViewDelegate,GDTNativeExpressAdDelegete,SearchDetailListCellDelegate,SearchTitleViewDelegate>{ |
| | | @interface searchDetailViewController ()<YTHSearchTextFieldDelegate,UITableViewDataSource,UITableViewDelegate,GDTNativeExpressAdDelegete,SearchDetailListCellDelegate,SearchTitleViewDelegate, SearchDelegate>{ |
| | | NSInteger pagenumber; |
| | | NSInteger typenumber; |
| | | //广点通原生广告 |
| | |
| | | @property (nonatomic, strong) SearchTitleView *viewSearchTitle; |
| | | |
| | | @property (nonatomic, strong) NSArray *typeList; |
| | | |
| | | @property (nonatomic, strong) SearchNavView *viewSearchNav; |
| | | @end |
| | | |
| | | @implementation searchDetailViewController |
| | |
| | | |
| | | } |
| | | |
| | | - (void)viewWillAppear:(BOOL)animated |
| | | { |
| | | - (void)viewWillAppear:(BOOL)animated { |
| | | [super viewWillAppear:animated]; |
| | | [self.navigationController setNavigationBarHidden:YES animated:animated]; |
| | | self.navigationController.navigationBar.translucent = NO; |
| | | } |
| | | |
| | | - (void)viewWillDisappear:(BOOL)animated |
| | | { |
| | | - (void)viewWillDisappear:(BOOL)animated { |
| | | [super viewWillDisappear:animated]; |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 设置导航栏 |
| | | */ |
| | | - (void)setNavgtionView { |
| | | UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW-115, 30)]; |
| | | YTHSearchTextField *searchField = [[YTHSearchTextField alloc] initWithFrame:CGRectMake(0, 0, titleView.frame.size.width, titleView.frame.size.height)]; |
| | | |
| | | searchField.delegate = self; |
| | | self.searchField = searchField; |
| | | searchField.layer.cornerRadius =searchField.frame.size.height / 2; |
| | | searchField.layer.masksToBounds = YES; |
| | | searchField.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.2]; |
| | | |
| | | [titleView addSubview:searchField]; |
| | | self.navigationItem.titleView = titleView; |
| | | //取消输入框的第一响应事件 |
| | | [searchField.Field resignFirstResponder]; |
| | | |
| | | searchField.Field.text = self.searchString; |
| | | |
| | | //加载用户搜索的数据 |
| | | //[self loadSearchData]; |
| | | |
| | | //定制返回按钮 |
| | | UIButton *backBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 50)]; |
| | | [backBtn setTitle:@"返回" forState:UIControlStateNormal]; |
| | | backBtn.titleLabel.font=[UIFont systemFontOfSize:14]; |
| | | [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| | | [backBtn addTarget:self action:@selector(backToMainVC:) forControlEvents:UIControlEventTouchUpInside]; |
| | | UIBarButtonItem *backItem=[[UIBarButtonItem alloc] initWithCustomView:backBtn]; |
| | | |
| | | //添加返回按钮到导航栏 |
| | | self.navigationItem.leftBarButtonItem=backItem; |
| | | |
| | | //定制搜索按钮 |
| | | UIButton *searchBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; |
| | | [searchBtn setImage:[UIImage imageNamed:@"搜索按钮"] forState:UIControlStateNormal]; |
| | | [searchBtn addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside]; |
| | | UIBarButtonItem *searchItem=[[UIBarButtonItem alloc] initWithCustomView:searchBtn]; |
| | | |
| | | //添加搜索按钮 |
| | | self.navigationItem.rightBarButtonItem=searchItem; |
| | | |
| | | self.view.backgroundColor = kGlobalBackgroundColor; |
| | | |
| | | [self.view addSubview:self.viewSearchTitle]; |
| | | // UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW-115, 30)]; |
| | | // YTHSearchTextField *searchField = [[YTHSearchTextField alloc] initWithFrame:CGRectMake(0, 0, titleView.frame.size.width, titleView.frame.size.height)]; |
| | | // |
| | | // searchField.delegate = self; |
| | | // self.searchField = searchField; |
| | | // searchField.layer.cornerRadius =searchField.frame.size.height / 2; |
| | | // searchField.layer.masksToBounds = YES; |
| | | // searchField.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.2]; |
| | | // |
| | | // [titleView addSubview:searchField]; |
| | | // self.navigationItem.titleView = titleView; |
| | | // //取消输入框的第一响应事件 |
| | | // [searchField.Field resignFirstResponder]; |
| | | // |
| | | // searchField.Field.text = self.searchString; |
| | | // |
| | | // //加载用户搜索的数据 |
| | | // //[self loadSearchData]; |
| | | // |
| | | // //定制返回按钮 |
| | | // UIButton *backBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 50)]; |
| | | // [backBtn setTitle:@"返回" forState:UIControlStateNormal]; |
| | | // backBtn.titleLabel.font=[UIFont systemFontOfSize:14]; |
| | | // [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| | | // [backBtn addTarget:self action:@selector(backToMainVC:) forControlEvents:UIControlEventTouchUpInside]; |
| | | // UIBarButtonItem *backItem=[[UIBarButtonItem alloc] initWithCustomView:backBtn]; |
| | | // |
| | | // //添加返回按钮到导航栏 |
| | | // self.navigationItem.leftBarButtonItem=backItem; |
| | | // |
| | | // //定制搜索按钮 |
| | | // UIButton *searchBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; |
| | | // [searchBtn setImage:[UIImage imageNamed:@"搜索按钮"] forState:UIControlStateNormal]; |
| | | // [searchBtn addTarget:self action:@selector(search:) forControlEvents:UIControlEventTouchUpInside]; |
| | | // UIBarButtonItem *searchItem=[[UIBarButtonItem alloc] initWithCustomView:searchBtn]; |
| | | // |
| | | // //添加搜索按钮 |
| | | // self.navigationItem.rightBarButtonItem=searchItem; |
| | | // |
| | | // self.view.backgroundColor = kGlobalBackgroundColor; |
| | | // |
| | | // [self.view addSubview:self.viewSearchTitle]; |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 添加用于显示的列表 |
| | | */ |
| | | -(void)addTabelView { |
| | | - (void)addTabelView { |
| | | [self.view addSubview:self.viewSearchNav]; |
| | | self.viewSearchNav.text = _searchString; |
| | | |
| | | __weak typeof(self) weakSelf = self; |
| | | self.viewSearchNav.onCacel = ^{ |
| | | [SVProgressHUD dismiss]; |
| | | if (weakSelf.suggestTableview.hidden) { |
| | | [weakSelf.view endEditing:YES]; |
| | | [weakSelf.navigationController popViewControllerAnimated:YES]; |
| | | |
| | | } else { |
| | | weakSelf.suggestTableview.hidden = YES; |
| | | weakSelf.DisplayTabelView.hidden = NO; |
| | | } |
| | | }; |
| | | |
| | | if(!self.DisplayTabelView) { |
| | | CGFloat height = 64; |
| | | if (KIsiPhoneX) { |
| | | height = 84; |
| | | } |
| | | self.DisplayTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, KScreenW, KScreenH - height - 40) style:UITableViewStyleGrouped]; |
| | | self.DisplayTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusBarH + ALNavBarH, KScreenW, KScreenH - kStatusBarH - ALNavBarH) style:UITableViewStyleGrouped]; |
| | | } |
| | | self.DisplayTabelView.delegate=self; |
| | | self.DisplayTabelView.dataSource=self; |
| | | |
| | | |
| | | //tableView背景色 |
| | | self.DisplayTabelView.backgroundColor = [UIColor whiteColor]; |
| | | self.DisplayTabelView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| | |
| | | //请求数据 |
| | | [self loadSearchData:NO]; |
| | | }]; |
| | | |
| | | [self loadSearchData:YES]; |
| | | //[self.DisplayTabelView.mj_header beginRefreshing]; |
| | | } |
| | | |
| | | |
| | | #pragma mark --------- SearchDelegate --------- |
| | | - (void)textFieldSearch:(NSString *)text { |
| | | if ([text isEqualToString:@""] || !text) { |
| | | return; |
| | | } |
| | | [self.view endEditing:YES]; |
| | | if (text.length > 0) { |
| | | _dataSearch = nil; |
| | | self.searchString = text; |
| | | [self.DisplayTabelView setHidden:NO]; |
| | | [self.suggestTableview setHidden:YES]; |
| | | [self.DisplayTabelView.mj_header beginRefreshing]; |
| | | |
| | | } else { |
| | | //提示用户搜索内容不能为空 |
| | | } |
| | | } |
| | | |
| | | - (void)textFieldValueChange:(NSString *)text { |
| | | if (text.length > 0) {//有值 |
| | | [self getSuggestSearchWithKey:text]; |
| | | self.DisplayTabelView.hidden = YES; |
| | | self.suggestTableview.hidden = NO; |
| | | |
| | | } else {//没有值 |
| | | self.DisplayTabelView.hidden = NO; |
| | | self.suggestTableview.hidden = YES; |
| | | } |
| | | } |
| | | |
| | | /// 请求搜索数据 |
| | | /// @param isSearch 是不是搜索来的数据 |
| | | -(void)loadSearchData:(BOOL)isSearch { |
| | | [self searchDataWithText:self.searchField.Field.text withType:typenumber withPage:pagenumber :isSearch]; |
| | | [self searchDataWithText:_searchString withType:typenumber withPage:pagenumber :isSearch]; |
| | | } |
| | | |
| | | /** |
| | |
| | | if (KIsiPhoneX) { |
| | | spaceTop = 84; |
| | | } |
| | | UITableView *suggestTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH - spaceTop) style:UITableViewStyleGrouped]; |
| | | UITableView *suggestTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, kStatusBarH + ALNavBarH, KScreenW, KScreenH - kStatusBarH - ALNavBarH) style:UITableViewStyleGrouped]; |
| | | [suggestTableview setBackgroundColor:[UIColor whiteColor]]; |
| | | suggestTableview.delegate = self; |
| | | suggestTableview.dataSource = self; |
| | | suggestTableview.hidden = YES; |
| | | suggestTableview.separatorStyle = UITableViewCellSeparatorStyleNone; |
| | | _suggestTableview = suggestTableview; |
| | | [self.view addSubview:suggestTableview]; |
| | | } |
| | |
| | | //没有数据,需要告诉用户 |
| | | |
| | | } |
| | | ++pagenumber; |
| | | pagenumber++; |
| | | [self.DisplayTabelView.mj_header endRefreshing]; |
| | | [self.DisplayTabelView.mj_footer endRefreshing]; |
| | | [self.DisplayTabelView reloadData]; |
| | |
| | | /*************(以下)协议*****************/ |
| | | #pragma mark -YTHSearchTextFieldDelegate |
| | | - (void)YTHSearchField:(YTHSearchTextField *)searchField SearchValueChanged:(UITextField *)textField{//实时监控 |
| | | |
| | | if (textField.text.length>0) {//有值 |
| | | [self getSuggestSearchWithKey:textField.text]; |
| | | [self.DisplayTabelView setHidden:YES]; |
| | | self.suggestTableview.hidden = NO; |
| | | }else{//没有值 |
| | | |
| | | } else {//没有值 |
| | | [self.DisplayTabelView setHidden:NO]; |
| | | self.suggestTableview.hidden = YES; |
| | | } |
| | |
| | | [self.suggestTableview setHidden:YES]; |
| | | [self.DisplayTabelView.mj_header beginRefreshing]; |
| | | [self.DisplayTabelView reloadData]; |
| | | }else{ |
| | | |
| | | } else { |
| | | //提示用户搜索内容不能为空 |
| | | } |
| | | return YES; |
| | |
| | | } |
| | | } |
| | | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| | | if (tableView==self.suggestTableview) { |
| | | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentfly]; |
| | | if (tableView == self.suggestTableview) { |
| | | SearchCell *cell = [tableView dequeueReusableCellWithIdentifier:indentfly]; |
| | | if (cell == nil) { |
| | | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentfly]; |
| | | cell = [[SearchCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentfly]; |
| | | } |
| | | cell.textLabel.text = [_suggestSearch objectAtIndex:indexPath.section]; |
| | | cell.title = _suggestSearch[indexPath.section]; |
| | | return cell; |
| | | |
| | | } else { |
| | |
| | | return CGFLOAT_MIN; |
| | | } |
| | | - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ |
| | | UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, 0.5)]; |
| | | UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, CGFLOAT_MIN)]; |
| | | view.backgroundColor = [UIColor clearColor]; |
| | | return view; |
| | | } |
| | | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ |
| | | if (section % 20 == 0 && self.expressAdViews.count != 0) { |
| | | if (section % 20 == 0 && self.expressAdViews.count != 0 && tableView != self.suggestTableview) { |
| | | NSInteger infoIndex; |
| | | if (self.expressAdViews.count <= (section / 20)) { |
| | | infoIndex = (section/20)%self.expressAdViews.count; |
| | | }else{ |
| | | |
| | | } else { |
| | | infoIndex = section / 20; |
| | | } |
| | | GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[infoIndex]; |
| | |
| | | } |
| | | } |
| | | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| | | if (section %20 == 0 && self.expressAdViews.count != 0) { |
| | | if (section %20 == 0 && self.expressAdViews.count != 0 && tableView != self.suggestTableview) { |
| | | NSInteger infoIndex; |
| | | if (self.expressAdViews.count <= (section / 20)) { |
| | | infoIndex = (section/20)%self.expressAdViews.count; |
| | |
| | | GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[infoIndex]; |
| | | adView.backgroundColor = kGlobalBackgroundColor; |
| | | return adView; |
| | | }else{ |
| | | } else { |
| | | UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, 0)]; |
| | | return view; |
| | | } |
| | |
| | | |
| | | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| | | if(tableView == self.suggestTableview) { |
| | | return 44; |
| | | return 55; |
| | | |
| | | } else { |
| | | XYRVideoInfoModel *model = [XYRVideoInfoModel yy_modelWithDictionary:_dataSearch[indexPath.section]]; |
| | |
| | | |
| | | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| | | [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| | | if(tableView==self.suggestTableview){ |
| | | _searchField.Field.text = [_suggestSearch objectAtIndex:indexPath.section]; |
| | | [self searchCotol:_searchField.Field.text]; |
| | | //[self.DisplayTabelView.mj_header beginRefreshing]; |
| | | [self searchDataWithText:self.searchField.Field.text withType:typenumber withPage:1 :YES]; |
| | | if(tableView == self.suggestTableview){ |
| | | NSString *name = [_suggestSearch objectAtIndex:indexPath.section]; |
| | | [self textFieldSearch:name]; |
| | | [self searchDataWithText:name withType:typenumber withPage:1 :YES]; |
| | | |
| | | } else { |
| | | XYRVideoInfoModel *model = [XYRVideoInfoModel yy_modelWithDictionary:_dataSearch[indexPath.section]]; |
| | |
| | | } |
| | | } |
| | | |
| | | - (SearchNavView *)viewSearchNav { |
| | | if (!_viewSearchNav) { |
| | | _viewSearchNav = [[SearchNavView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, kStatusBarH + ALNavBarH)]; |
| | | _viewSearchNav.delegate = self; |
| | | } |
| | | return _viewSearchNav; |
| | | } |
| | | |
| | | - (SearchTitleView *)viewSearchTitle { |
| | | if (!_viewSearchTitle) { |
| | | _viewSearchTitle = [[SearchTitleView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 40)]; |