admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
//
//  searchViewController.m
//  BuWanVideo2.0
//
//  Created by weikou on 16/8/17.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "searchViewController.h"
#import "YTHSearchTextField.h"
 
#import "searchDetailViewController.h"
#import "SearchCollectionViewCell.h"
#import "SearchCollectionReusableView.h"
#import "searchTableViewCell.h"
 
//广点通原生广告的头文件
#import "ADCollectionReusableView.h"
//#import "GDTNativeAd.h"
#import "GDTNativeExpressAd.h"
#import "GDTNativeExpressAdView.h"
#import "FaxianCReusableView.h"
 
@interface searchViewController ()<YTHSearchTextFieldDelegate,UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,GDTNativeExpressAdDelegete>{
    //广点通原生广告
    //    GDTNativeAd *_nativeAd;     //原生广告实例
    //    NSMutableArray  *nativeArray;//存储请求下来的原生广告信息
}
@property (nonatomic , strong) UICollectionView *collectionView;
 
@property (nonatomic , strong) YTHSearchTextField *searchField;//搜索框对象
@property (nonatomic , strong) NSString *searchString;//搜索框上面的搜索字符串
 
@property (weak, nonatomic) UITableView *suggestTableview;//模糊搜索弹出的表格
@property (nonatomic , strong) NSMutableArray *suggestSearch;//搜索建议
 
@property (nonatomic , strong) NSMutableArray *dataHot;//热门搜索
@property (nonatomic , strong) NSMutableArray *dataOld;//历史搜索
 
@property (nonatomic , strong) NSMutableArray *historySearchArray;//存放历史搜索记录的数组
 
@property (nonatomic, strong) NSArray *expressAdViews;
@property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd;
@end
 
@implementation searchViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    //定制导航栏
    [self setNavgtionView];
    //添加搜索建议的tableview
    [self addsuggestTableview];
    //添加搜索视图
    [self addSearchCollectionView];
    //请求数据
    [self getData];
}
 
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear: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.layer.cornerRadius =searchField.frame.size.height / 2;
    searchField.layer.masksToBounds = YES;
    searchField.delegate = self;
    searchField.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.2];
    self.searchField = searchField;
    [titleView addSubview:searchField];
    self.navigationItem.titleView = titleView;
    [searchField.Field resignFirstResponder];
    if ([YTHsharedManger startManger].searchTitle) {
        searchField.Field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:[YTHsharedManger startManger].searchTitle attributes:@{NSForegroundColorAttributeName:[UIColor colorWithWhite:0.7 alpha:0.9]}];
    }
    //定制返回按钮
    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;
}
 
 
 
/**
 *  添加搜索建议的tableView
 */
-(void)addsuggestTableview{
    UITableView *suggestTableview = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    [suggestTableview setBackgroundColor:[UIColor whiteColor]];
    suggestTableview.delegate = self;
    suggestTableview.dataSource = self;
    suggestTableview.hidden = YES;
    _suggestTableview = suggestTableview;
    [self.view addSubview:suggestTableview];
}
 
-(void)addSearchCollectionView{
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    //指定布局方式为垂直
    flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    flow.minimumLineSpacing = 5;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
    flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距
    CGFloat height = 64;
    if (KIsiPhoneX) {
        height = 84;
    }
    //创建CollectionView并指定布局对象
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH - height) collectionViewLayout:flow];
    _collectionView.backgroundColor = kGlobalBackgroundColor;
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.delaysContentTouches=NO;
    [self.view addSubview:_collectionView];
    
    //注册cell
    [_collectionView registerNib:[UINib nibWithNibName:@"SearchCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"SearchCollectionViewCellID"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"SearchCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SearchCollectionReusableViewID"];
    //设置尾部芒果广告的foot
    [self.collectionView registerNib:[UINib nibWithNibName:@"ADCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"FaxianCReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FaxianCReusableView"];
    
}
 
 
/**
 *  返回到主视图
 *
 *  @param sender 返回按钮
 */
-(void)backToMainVC:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
 
 
 
/**
 *  点击搜索按钮
 *
 *  @param sender 搜索按钮
 */
-(void)search:(UIButton *)sender{
    if (_searchField.Field.text.length>0) {
        [self searchCotol:_searchField.Field.text];
    }else if(_searchField.Field.placeholder.length > 0){
        [self searchCotol:_searchField.Field.placeholder];
    }
}
 
 
-(void)clickADs{
    //    GDTNativeAdData * info =nativeArray[0];
    //    [_nativeAd clickAd:info];
}
 
 
/**
 *  搜索建议
 *
 *  @param text 用户搜索输入的文字
 */
- (void)getSuggestSearchWithKey:(NSString *)text{
    _suggestSearch = nil;
    [[YTHNetInterface startInterface] getSuggestSearchWithUid:[YTHsharedManger startManger].Uid withKey:text withSystem:@"1" withPage:@"1" withblock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            if (!_suggestSearch) {
                _suggestSearch = [[NSMutableArray alloc]initWithCapacity:0];
            }
            _suggestSearch = [[result objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i <_suggestSearch.count; i++){
                NSLog(@"%@",[_suggestSearch objectAtIndex:i]);
            }
            [_suggestTableview reloadData];
        }else{
            //当前网络不稳定
        }
    }];
}
 
/**
 *  点击搜索执行方法
 *
 *  @param text 输入框的内容
 */
- (void)searchCotol:(NSString *)text {
    [_searchField.Field resignFirstResponder];
    searchDetailViewController *sresult = [[searchDetailViewController alloc] init];
    if (_searchField.Field.text.length <1) {
        sresult.searchString = _searchField.Field.placeholder;
        [self writeAndReadHistorySearchToFile:_searchField.Field.placeholder];
        
    }else{
        sresult.searchString = text;
        [self writeAndReadHistorySearchToFile:text];
    }
    [self getOldSearch];
    [self.navigationController pushViewController:sresult animated:YES];
}
 
/**
 *  将历史搜索写入文件
 *
 *  @param historySearch 输入框的内容
 */
-(NSArray *)writeAndReadHistorySearchToFile:(NSString *)historySearch{
    if(!_historySearchArray){
        _historySearchArray = [NSMutableArray arrayWithCapacity:0];
    }
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:HISTORYSEARCHFILE]){
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_historySearchArray];
        [fileManager createFileAtPath:HISTORYSEARCHFILE contents:data attributes:nil];
        if (historySearch) {
            [_historySearchArray addObject:historySearch];
            NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_historySearchArray];
            [data writeToFile:HISTORYSEARCHFILE atomically:YES];
        }
        return _historySearchArray;
    }
    else{
        _historySearchArray=[NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:HISTORYSEARCHFILE]];
        if (historySearch){
            if (_historySearchArray.count >=10){
                [_historySearchArray removeObjectAtIndex:0];
            }
            for (int i=0; i<_historySearchArray.count; i++){
                if ([[_historySearchArray objectAtIndex:i] isEqual:historySearch]){
                    return _historySearchArray;
                }
            }
            [_historySearchArray addObject:historySearch];
            NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_historySearchArray];
            [data writeToFile:HISTORYSEARCHFILE atomically:YES];
        }
    }
    return _historySearchArray;
}
 
/**
 *  请求数据
 */
- (void)getData{
    [self getHotSearch];
    [self getOldSearch];
    [self loadAd];
}
 
/**
 *  热门搜索
 */
- (void)getHotSearch{
    [[YTHNetInterface startInterface] getHotSerachWithUid:[YTHsharedManger startManger].Uid withSystem:@"1" withblock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *dic = (NSDictionary *)result;
            if (!_dataHot) {
                _dataHot = [[NSMutableArray alloc] initWithCapacity:0];
            }
            [_dataHot removeAllObjects];
            NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i<ar.count; i++) {
                [_dataHot addObject:[ar objectAtIndex:i]];
            }
            //            self.searchField
            //刷新热门搜索
            [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
        }else{
            if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
                [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
            }
            //显示网络连接失败
        }
    }];
}
 
/**
 *  历史搜索 读取本地搜素记录
 */
- (void)getOldSearch{
    _dataOld = (NSMutableArray *)[self writeAndReadHistorySearchToFile:nil];
    //刷新本地记录
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
}
 
/**
 *  加载广点通原生广告
 */
-(void)loadAd{
    //    _nativeAd = [[GDTNativeAd alloc] initWithAppkey:GDTADkey placementId:GDTYSADkey3];
    //    _nativeAd.controller = self;
    //    _nativeAd.delegate = self;
    //    [_nativeAd loadAd:1];
    // 支持视频广告的 PlacementId 会混出视频与图片广告
    self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithPlacementId:GDTYSADkey3 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)];
    self.nativeExpressAd.delegate = self;
    // 配置视频播放属性
    self.nativeExpressAd.videoAutoPlayOnWWAN = YES;
    self.nativeExpressAd.videoMuted = NO;
    [self.nativeExpressAd loadAd:2];
}
- (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd
                                      *)nativeExpressAd views:(NSArray<__kindof
                                                               GDTNativeExpressAdView *> *)views
{
    self.expressAdViews = [NSArray arrayWithArray:views];
    if (self.expressAdViews.count) {
        [self.expressAdViews enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
            expressView.controller = self;
            [expressView render];
        }];
    }
    // 广告位 render 后刷新 tableView
    [_collectionView reloadData];
}
- (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{
    NSLog(@"%@",error);
}
 
/**
 *  清除历史记录
 *
 *  @param sender 清除的按钮
 */
-(void)ClearHistorys:(UIButton *)sender{
    [_dataOld removeAllObjects];
    [self deleteFile:HISTORYSEARCHFILE];
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
}
 
 
/**
 *  删除沙盒里的文件
 *
 *  @param filePath 要删除的文件
 */
-(void)deleteFile:(NSString *)filePath {
    NSFileManager* fileManager=[NSFileManager defaultManager];
    BOOL blHave=[fileManager fileExistsAtPath:filePath];
    if (!blHave) {
        NSLog(@"no  have");
        return ;
    }else {
        NSLog(@"have");
        BOOL blDele= [fileManager removeItemAtPath:filePath error:nil];
        if (blDele) {
            NSLog(@"dele success");
        }else {
            NSLog(@"dele fail");
        }
    }
}
 
/***************(以下)协议方法***************/
#pragma mark -GDTNativeAdDelegate
/**
 *  原生广告加载广告数据成功回调,返回为GDTNativeAdData对象的数组
 */
//-(void)nativeAdSuccessToLoad:(NSArray *)nativeAdDataArray{
//    if (!nativeArray) {
//        nativeArray =[[NSMutableArray alloc]initWithArray:nativeAdDataArray];
//    }else{
//        [nativeArray addObjectsFromArray:nativeAdDataArray];
//    }
//    [_collectionView reloadData];
//}
 
/**
 *  原生广告加载广告数据失败回调
 */
//-(void)nativeAdFailToLoad:(NSError *)error{
//    NSLog(@"XYR_%@",error);
//}
 
#pragma mark -YTHSearchTextFieldDelegate
- (void)YTHSearchField:(YTHSearchTextField *)searchField SearchValueChanged:(UITextField *)textField{//实时监控
    if (textField.text.length>0) {
        _suggestTableview.hidden = NO;
        _collectionView.hidden=YES;
        NSLog(@"有数据");
        [self getSuggestSearchWithKey:textField.text];
    }else{
        _suggestTableview.hidden = YES;
        _collectionView.hidden=NO;
        NSLog(@"无数据");
    }
}
 
- (BOOL)YTHSearchField:(YTHSearchTextField *)searchField textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"点击了键盘搜索");
    if (textField.text.length>0) {
        [self searchCotol:textField.text];
    }
    return YES;
}
 
- (void)YTHSearchField:(YTHSearchTextField *)searchField clearClik:(UIButton *)btn{//点击清除按钮
    self.suggestTableview.hidden = YES;
    self.collectionView.hidden=NO;
    [self getOldSearch];
}
 
#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _suggestSearch.count;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentfly = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentfly];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentfly];
    }
    cell.textLabel.text = [_suggestSearch objectAtIndex:indexPath.row];
    return cell;
}
 
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
 
//点击建议搜索进行搜索
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    _searchField.Field.text = [_suggestSearch objectAtIndex:indexPath.row];
    [self searchCotol:_searchField.Field.text];
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
    [tableView reloadData];
}
 
#pragma mark -UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section==0) {
        if (_dataHot.count<10) {
            return _dataHot.count;
        }
        return 10;
    }else if(section==1){
        if(_dataOld.count<10){
            return _dataOld.count;
        }else{
            return 10;
        }
    }else{
        return 0;
    }
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SearchCollectionViewCell *Cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"SearchCollectionViewCellID" forIndexPath:indexPath];
    if (indexPath.section==0) {//热门搜索的cell
        Cell.searchCellText.text=_dataHot[indexPath.row];
        [Cell.backgroundColor setHidden:YES];
        UIImage *deselectImage;
        if (indexPath.row%2==0) {//热门搜索单双数的cell背景不同,需要分别设置
            deselectImage=[UIImage imageNamed:@"热门搜索头"];
        }else{
            deselectImage=[UIImage imageNamed:@"热门搜索尾"];
        }
        deselectImage=[deselectImage stretchableImageWithLeftCapWidth:floorf(deselectImage.size.width/2) topCapHeight:floorf(deselectImage.size.height/2)];
        [Cell.searchCellBackImage setImage:deselectImage];
    }else{
        //历史搜索的cell
        Cell.searchCellText.text=_dataOld[_dataOld.count-indexPath.row-1];
        Cell.searchCellText.backgroundColor=[UIColor whiteColor];
        [Cell.searchCellBackImage setHidden:YES];
    }
    return Cell;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}
//定制collectionView的head和foot
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader){
        SearchCollectionReusableView *searchV=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SearchCollectionReusableViewID" forIndexPath:indexPath];
        if (indexPath.section==0) {
            searchV.searchViewTitle.text=@"热门搜索";
            [searchV.ClearHistory setHidden:YES];
        }else{
            searchV.searchViewTitle.text=@"历史搜索";
            [searchV.ClearHistory addTarget:self action:@selector(ClearHistorys:) forControlEvents:UIControlEventTouchUpInside];
        }
        return searchV;
    }else if (kind == UICollectionElementKindSectionFooter){
        if (indexPath.section==1) {
            //返回广告视图
            ADCollectionReusableView *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView" forIndexPath:indexPath];
            //            GDTNativeAdData *info=nativeArray[0];
            //
            //            groupfootSection.ADTitle.text=[info.properties objectForKey:GDTNativeAdDataKeyTitle];
            //            groupfootSection.ADTitle.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
            //            [groupfootSection.ADImage setYthImageWithURL:[info.properties objectForKey:GDTNativeAdDataKeyImgUrl] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
            //            //把button设为透明
            //            groupfootSection.ADClickButton.backgroundColor=[UIColor clearColor];
            //            [groupfootSection.ADClickButton addTarget:self action:@selector(clickADs) forControlEvents:UIControlEventTouchUpInside];
            //            [_nativeAd attachAd:info toView:groupfootSection];
            GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[0];
            //              FaxianCReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FaxianCReusableView" forIndexPath:indexPath];
            //            [view addSubview:groupfootSection];
            [groupfootSection addSubview:adView];
            return groupfootSection;
            //            return view;
            
        }
    }
    return nil;
}
#pragma mark -UICollectionViewDelegate
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    SearchCollectionViewCell *Cell=(SearchCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    self.searchField.Field.text=Cell.searchCellText.text;
    if (_searchField.Field.text.length>0) {
        [self searchCotol:_searchField.Field.text];
    }
}
#pragma mark -UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return CGSizeMake((KScreenW-40)/2, 30);
    }else if(indexPath.section==1){
        NSString *IntroductionStr=_dataOld[_dataOld.count-indexPath.row-1];
        CGSize IntroSize = [IntroductionStr boundingRectWithSize:CGSizeMake(MAXFLOAT, 25) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
        
        CGSize titleSize=CGSizeMake((IntroSize.width+10)<(KScreenW-40)/2?IntroSize.width+30:(KScreenW-50)/2, 25);
        return titleSize;
    }
    CGSize defaultSize=CGSizeMake(0.0f, 0.0f);
    return defaultSize;
}
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if(section==0){
        //上、左、下、右的边距
        return UIEdgeInsetsMake(0, 15, 10, 15);
    }else if(section==1){
        return UIEdgeInsetsMake(10, 15, 10, 15);
    }else{
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
}
 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    //宽度随便定,系统会自动取collectionView的宽度
    //高度为分组头的高度
    if(section==0){
        return CGSizeMake(0, 50);
    }else{
        return CGSizeMake(0, 30);
    }
}
 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    if(section==1){
        if (self.expressAdViews==nil) {
            return CGSizeMake(0, 0);
        }else{
            UIView *view = self.expressAdViews[0];
            
            return CGSizeMake(0, view.bounds.size.height);
        }
    }else{
        return CGSizeMake(0, 0);
    }
}
 
@end