GromoreDemoAdStatusCell.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // ABUDemoAdStatusInfoCell.m
  3. // ABUDemo
  4. //
  5. // Created by heyinyin on 2021/12/15.
  6. // Copyright © 2021 bytedance. All rights reserved.
  7. //
  8. #import "GromoreDemoAdStatusCell.h"
  9. #import "GromoreDemoAdCallbackCell.h"
  10. NSString *const GromoreDemoAdStatusCellReviceRecordNotification = @"GromoreDemoAdStatusCellReviceRecordNotification";
  11. NSString *const GromoreDemoAdStatusCellReviceClearNotification = @"GromoreDemoAdStatusCellReviceClearNotification";
  12. NSString *const GromoreDemoAdStatusCellReviceRecordKey = @"record";
  13. static NSString *adSelectCell = @"GROMORE_DEMO_CALLBACK_CELL";
  14. @interface GromoreDemoAdStatusCell () <UITableViewDataSource,UITableViewDelegate>
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) NSMutableArray *list;
  17. @end
  18. @implementation GromoreDemoAdStatusCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  20. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  21. [self initTableView];
  22. }
  23. self.selectionStyle = UITableViewCellSelectionStyleNone;
  24. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveRecord:) name:GromoreDemoAdStatusCellReviceRecordNotification object:nil];
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveClear:) name:GromoreDemoAdStatusCellReviceClearNotification object:nil];
  26. return self;
  27. }
  28. - (void)initTableView {
  29. if (!_tableView) {
  30. CGRect frame = (CGRect){0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), 220}; // _basicInfo.count
  31. _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
  32. _tableView.delegate = self;
  33. _tableView.dataSource = self;
  34. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  35. [self.contentView addSubview:_tableView];
  36. [_tableView registerClass:[GromoreDemoAdCallbackCell class] forCellReuseIdentifier:adSelectCell];
  37. }
  38. }
  39. #pragma mark ---- UITableViewDelegate, UITableViewDataSource ----
  40. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  41. GromoreDemoAdCallbackCell *cell = (GromoreDemoAdCallbackCell *)[tableView dequeueReusableCellWithIdentifier:adSelectCell];
  42. NSString *text = self.list[indexPath.row];
  43. [cell setCallbackRecord:text];
  44. return cell;
  45. }
  46. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  47. return nil;
  48. }
  49. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  50. return nil;
  51. }
  52. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  53. return 0.f;
  54. }
  55. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  56. return 0.f;
  57. }
  58. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  59. return 40.f;
  60. }
  61. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  62. return self.list.count;
  63. }
  64. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  65. /// 处理点击事件,显示对应选择广告信息
  66. }
  67. #pragma mark - Notice
  68. - (void)didReceiveRecord:(NSNotification *)notification {
  69. NSString *record = notification.userInfo[GromoreDemoAdStatusCellReviceRecordKey];
  70. [self.list addObject:record];
  71. [self reloadTableView];
  72. }
  73. - (void)didReceiveClear:(NSNotification *)notification {
  74. if (self.list.count > 0) {
  75. [self.list removeAllObjects];
  76. [self reloadTableView];
  77. }
  78. }
  79. - (void)reloadTableView {
  80. [self.tableView reloadData];
  81. }
  82. #pragma mark - Getter && Setter
  83. - (NSMutableArray *)list {
  84. if (!_list) {
  85. _list = [NSMutableArray array];
  86. }
  87. return _list;
  88. }
  89. @end