RQUnDoProjectTableViewCell.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // RQUnDoProjectTableViewCell.m
  3. // NiuBi
  4. //
  5. // Created by 张嵘 on 2023/3/14.
  6. //
  7. #import "RQUnDoProjectTableViewCell.h"
  8. #import "GDTNativeExpressAd.h"
  9. #import "GDTNativeExpressAdView.h"
  10. @interface RQUnDoProjectTableViewCell () <GDTNativeExpressAdDelegete>
  11. @property (nonatomic, readwrite, strong) RQUnDoProjectTableViewItemViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) NSArray *expressAdViews;
  13. @property (weak, nonatomic) IBOutlet UIView *myAdView;
  14. @property (nonatomic, readwrite, strong) GDTNativeExpressAd *nativeExpressAd;
  15. @end
  16. @implementation RQUnDoProjectTableViewCell
  17. + (instancetype)cellWithTableView:(UITableView *)tableView {
  18. static NSString *ID = @"RQUnDoProjectTableViewCell";
  19. RQUnDoProjectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  20. if (!cell) {
  21. cell = [self rq_viewFromXib];
  22. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  23. }
  24. return cell;
  25. }
  26. - (void)bindViewModel:(RQUnDoProjectTableViewItemViewModel *)viewModel {
  27. _viewModel = viewModel;
  28. }
  29. - (void)awakeFromNib {
  30. [super awakeFromNib];
  31. // 支持视频广告的 PlacementId 会混出视频与图片广告
  32. self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithPlacementId:@"4085226003670734" adSize:CGSizeMake(RQ_SCREEN_WIDTH - 32.f, (RQ_SCREEN_WIDTH - 32.f) * (3.f / 4.f))];
  33. self.nativeExpressAd.delegate = self;
  34. [self.nativeExpressAd loadAd:1];
  35. }
  36. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  37. [super setSelected:selected animated:animated];
  38. // Configure the view for the selected state
  39. }
  40. - (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd
  41. *)nativeExpressAd views:(NSArray<__kindof
  42. GDTNativeExpressAdView *> *)views {
  43. @weakify(self)
  44. self.expressAdViews = [NSArray arrayWithArray:views];
  45. if (self.expressAdViews.count) {
  46. [self.expressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  47. @strongify(self)
  48. GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
  49. [self.myAdView addSubview:expressView];
  50. expressView.controller = RQControllerHelper.currentViewController;
  51. if ([expressView isAdValid]) {
  52. [expressView render];
  53. }
  54. }];
  55. }
  56. }
  57. - (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error {
  58. }
  59. @end