GromoreDemoAdBasicInfoCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // ABUDemoBasicInfoCell.m
  3. // ABUDemo
  4. //
  5. // Created by heyinyin on 2021/12/15.
  6. // Copyright © 2021 bytedance. All rights reserved.
  7. //
  8. #import "GromoreDemoAdBasicInfoCell.h"
  9. #import "GromoreDemoAdBasicInfoSelectCell.h"
  10. #import "GromoreAdLoadConfig.h"
  11. static NSString *adSelectCell = @"GROMORE_DEMO_BASIC_INFO_SELECT_CELL";
  12. @interface GromoreDemoAdBasicInfoCell () <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
  13. // 广告基本信息
  14. @property (nonatomic, copy) NSArray<GromoreAdLoadConfig *> *adBasicInfo;
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @end
  17. @implementation GromoreDemoAdBasicInfoCell
  18. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  19. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  20. [self info];
  21. [self initTableView];
  22. }
  23. return self;
  24. }
  25. - (void)info {
  26. NSArray *list = @[
  27. @{ @"slotID" : @"945494753" , @"adType" : @(GromoreAdTypeBanner) , @"adDesc" : @"banner广告" },
  28. @{ @"slotID" : @"887383142" , @"adType" : @(GromoreAdTypeSplash) , @"adDesc" : @"开屏广告" },
  29. @{ @"slotID" : @"887418500" , @"adType" : @(GromoreAdTypeSplash) , @"adDesc" : @"开屏广告" },
  30. @{ @"slotID" : @"945494755" , @"adType" : @(GromoreAdTypeInterstitial) , @"adDesc" : @"插屏广告" },
  31. @{ @"slotID" : @"945494760" , @"adType" : @(GromoreAdTypeNative) , @"adDesc" : @"自渲染native广告" },
  32. @{ @"slotID" : @"945494759" , @"adType" : @(GromoreAdTypeNative) , @"adDesc" : @"模板native广告" },
  33. @{ @"slotID" : @"945494761" , @"adType" : @(GromoreAdTypeNative) , @"adDesc" : @"模板native广告" },
  34. @{ @"slotID" : @"945494747" , @"adType" : @(GromoreAdTypeRewardedVideo) , @"adDesc" : @"激励广告" },
  35. @{ @"slotID" : @"945494739" , @"adType" : @(GromoreAdTypeRewardedVideo) , @"adDesc" : @"激励广告" },
  36. @{ @"slotID" : @"945490586" , @"adType" : @(GromoreAdTypeRewardedVideo) , @"adDesc" : @"激励广告" },
  37. @{ @"slotID" : @"945494751" , @"adType" : @(GromoreAdTypeFullscreenVideo) , @"adDesc" : @"全屏广告" },
  38. @{ @"slotID" : @"945494752" , @"adType" : @(GromoreAdTypeFullscreenVideo) , @"adDesc" : @"全屏广告" },
  39. @{ @"slotID" : @"946961656" , @"adType" : @(GromoreAdTypeInterstitialPro) , @"adDesc" : @"插全屏广告" },
  40. @{ @"slotID" : @"948388643" , @"adType" : @(GromoreAdTypeDraw) , @"adDesc" : @"draw广告" }
  41. ];
  42. NSMutableArray *temp = [NSMutableArray arrayWithCapacity:list.count];
  43. [list enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
  44. GromoreAdLoadConfig *config = [[GromoreAdLoadConfig alloc] init];
  45. config.slotID = obj[@"slotID"];
  46. config.adType = [obj[@"adType"] integerValue];
  47. config.adDesc = obj[@"adDesc"];
  48. [temp addObject:config];
  49. }];
  50. self.adBasicInfo = [temp copy];
  51. }
  52. - (void)initTableView {
  53. if (!_tableView) {
  54. CGRect frame = (CGRect){0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), 35 * 3}; // _basicInfo.count
  55. _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
  56. _tableView.delegate = self;
  57. _tableView.dataSource = self;
  58. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  59. [self.contentView addSubview:_tableView];
  60. [_tableView registerClass:[GromoreDemoAdBasicInfoSelectCell class] forCellReuseIdentifier:adSelectCell];
  61. }
  62. }
  63. #pragma mark ---- UITableViewDelegate, UITableViewDataSource ----
  64. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  65. GromoreDemoAdBasicInfoSelectCell *cell = (GromoreDemoAdBasicInfoSelectCell *)[tableView dequeueReusableCellWithIdentifier:adSelectCell];
  66. if (_adBasicInfo.count > indexPath.row) {
  67. GromoreAdLoadConfig *config = [_adBasicInfo objectAtIndex:indexPath.row];
  68. [cell setCellInfoWithAdType:config.adDesc andAdId:config.slotID];
  69. }
  70. return cell;
  71. }
  72. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  73. return nil;
  74. }
  75. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  76. return nil;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  79. return 0.f;
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  82. return 0.f;
  83. }
  84. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  85. return 35.f;
  86. }
  87. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  88. return _adBasicInfo.count;
  89. }
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  91. /// 处理点击事件,显示对应选择广告信息
  92. if (_adBasicInfo.count > indexPath.row) {
  93. GromoreAdLoadConfig *config = [_adBasicInfo objectAtIndex:indexPath.row];
  94. if ([self.delegate respondsToSelector:@selector(didSelectAdConfig:)]) {
  95. [self.delegate didSelectAdConfig:config];
  96. }
  97. }
  98. }
  99. @end