| | |
| | | // Created by Aeline on 2021/5/30. |
| | | // Copyright © 2021 com.yeshi.buwansheque.ios. All rights reserved. |
| | | // |
| | | |
| | | #import "AppDelegate.h" |
| | | #import "SearchController.h" |
| | | #import "searchDetailViewController.h" |
| | | |
| | |
| | | #import "SearchHotCell.h" |
| | | #import "SearchRecordCell.h" |
| | | #import "SearchHotSearchCell.h" |
| | | #import "SearchADCell.h" |
| | | #import "SearchRecordHeaderView.h" |
| | | |
| | | #import "UICollectionViewLeftAlignedLayout.h" |
| | | #import "GDTNativeExpressAd.h" |
| | | #import "GDTNativeExpressAdView.h" |
| | | |
| | | @interface SearchController () <UICollectionViewDelegate, UICollectionViewDataSource, SearchDelegate, UITableViewDelegate, UITableViewDataSource> |
| | | @interface SearchController () <UICollectionViewDelegate, UICollectionViewDataSource, SearchDelegate, UITableViewDelegate, UITableViewDataSource,GDTNativeExpressAdDelegete> |
| | | |
| | | @property (nonatomic, strong) SearchNavView *viewSearchNav; |
| | | @property (nonatomic, nullable, strong) UICollectionView *collectionView; |
| | |
| | | @property (nonatomic, nullable, strong) NSDictionary *dictionaryHotSerch; |
| | | |
| | | @property (nonatomic, nullable, strong) NSMutableArray *arraySearch; |
| | | |
| | | @property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd; |
| | | @end |
| | | |
| | | @implementation SearchController |
| | |
| | | [self.collectionView reloadData]; |
| | | }); |
| | | }); |
| | | |
| | | [self loadAd]; |
| | | } |
| | | |
| | | - (void)setupViewConfig { |
| | |
| | | [self.tableView reloadData]; |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加载广点通原生广告 |
| | | */ |
| | | -(void)loadAd{ |
| | | self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithAppId:GDTADkey placementId:GDTYSADkey4 adSize:CGSizeMake(KScreenW-20, (KScreenW-20)/16*9 + 10)]; |
| | | self.nativeExpressAd.delegate = self; |
| | | // 配置视频播放属性 |
| | | self.nativeExpressAd.videoAutoPlayOnWWAN = YES; |
| | | self.nativeExpressAd.videoMuted = NO; |
| | | [self.nativeExpressAd loadAd:1]; |
| | | } |
| | | - (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd |
| | | *)nativeExpressAd views:(NSArray<__kindof |
| | | GDTNativeExpressAdView *> *)views |
| | | { |
| | | GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)views[0]; |
| | | |
| | | |
| | | adView.controller = self; |
| | | [adView render]; |
| | | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:3]; |
| | | UICollectionViewCell *cell = (UICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; |
| | | cell.sd_layout.leftSpaceToView(self, 10); |
| | | [cell addSubview:adView]; |
| | | // 广告位 render 后刷新 tableView |
| | | [self.collectionView reloadData]; |
| | | } |
| | | - (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{ |
| | | NSLog(@"%@",error); |
| | | } |
| | | |
| | | #pragma mark ---------- SearchDelegate --------- |
| | |
| | | } |
| | | |
| | | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { |
| | | return 3; |
| | | return 4; |
| | | } |
| | | |
| | | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { |
| | |
| | | |
| | | } else if (section == 1) { |
| | | return self.arrayRecord.count; |
| | | |
| | | } else { |
| | | return 1; |
| | | } |
| | |
| | | cell.name = self.arrayRecord[indexPath.row]; |
| | | return cell; |
| | | |
| | | } else if (indexPath.section == 2) { |
| | | SearchHotSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SearchHotSearchCell" forIndexPath:indexPath]; |
| | | cell.delegate = self; |
| | | cell.data = _dictionaryHotSerch; |
| | | return cell; |
| | | |
| | | }else if (indexPath.section == 3) { |
| | | SearchADCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SearchADCell" forIndexPath:indexPath]; |
| | | return cell; |
| | | } else { |
| | | SearchHotSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SearchHotSearchCell" forIndexPath:indexPath]; |
| | | cell.delegate = self; |
| | |
| | | return CGSizeMake(KScreenW, 0); |
| | | } |
| | | return CGSizeMake(KScreenW, 20 + 16 + 16); |
| | | }else if (section == 3) { |
| | | return CGSizeMake(KScreenW, 10); |
| | | } |
| | | return CGSizeMake(KScreenW, 28); |
| | | } |
| | |
| | | [_collectionView registerClass:[SearchHotCell class] forCellWithReuseIdentifier:@"SearchHotCell"]; |
| | | [_collectionView registerClass:[SearchRecordCell class] forCellWithReuseIdentifier:@"SearchRecordCell"]; |
| | | [_collectionView registerClass:[SearchHotSearchCell class] forCellWithReuseIdentifier:@"SearchHotSearchCell"]; |
| | | [_collectionView registerClass:[SearchADCell class] forCellWithReuseIdentifier:@"SearchADCell"]; |
| | | |
| | | |
| | | |
| | | [_collectionView registerClass:[SearchRecordHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SearchRecordHeaderView"]; |
| | | |