重庆迈尖科技有限公司
2021-08-11 6d4592fd614cdf3301d5d26399a923c0ebc81b5e
BuWanVideo2.0/SearchController.m
@@ -5,7 +5,7 @@
//  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"
@@ -14,11 +14,14 @@
#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;
@@ -29,6 +32,8 @@
@property (nonatomic, nullable, strong) NSDictionary *dictionaryHotSerch;
@property (nonatomic, nullable, strong) NSMutableArray *arraySearch;
@property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd;
@end
@implementation SearchController
@@ -105,6 +110,8 @@
            [self.collectionView reloadData];
        });
    });
    [self loadAd];
}
- (void)setupViewConfig {
@@ -156,6 +163,38 @@
            [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 ---------
@@ -219,7 +258,7 @@
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 3;
    return 4;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
@@ -228,7 +267,6 @@
        
    } else if (section == 1) {
        return self.arrayRecord.count;
    } else {
        return 1;
    }
@@ -244,6 +282,15 @@
        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;
@@ -277,6 +324,8 @@
            return CGSizeMake(KScreenW, 0);
        }
        return CGSizeMake(KScreenW, 20 + 16 + 16);
    }else if (section == 3) {
        return CGSizeMake(KScreenW, 10);
    }
    return CGSizeMake(KScreenW, 28);
}
@@ -344,6 +393,9 @@
        [_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"];