RQTestQuestionsViewController.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // RQTestQuestionsViewController.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/8/12.
  6. //
  7. #import "RQTestQuestionsViewController.h"
  8. @interface RQTestQuestionsViewController ()
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQTestQuestionsViewModel *viewModel;
  11. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  12. @end
  13. @implementation RQTestQuestionsViewController
  14. @dynamic viewModel;
  15. #pragma mark - SystemMethod
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. /// 初始化
  19. [self rq_setup];
  20. }
  21. - (void)viewWillLayoutSubviews {
  22. [super viewWillLayoutSubviews];
  23. [self updateFrame];
  24. }
  25. - (void)updateFrame {
  26. CGFloat height = RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(50.f) - (RQ_AD_MANAGER.bannerIsShow? RQ_SCREEN_WIDTH / (640/100.0) : 0.f );
  27. self.tableView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, height);
  28. }
  29. - (void)dealloc {
  30. [[NSNotificationCenter defaultCenter] removeObserver:self];
  31. }
  32. #pragma mark - PrivateMethods
  33. /// 初始化
  34. - (void)rq_setup {
  35. @weakify(self)
  36. self.tableView.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR;
  37. // RQ_Exercise_Module.currrentExerciseModel = self.viewModel.exerciseModel;
  38. [[[[RACObserve(RQ_AD_MANAGER, bannerIsShow) deliverOnMainThread] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) {
  39. @strongify(self)
  40. [self updateFrame];
  41. }];
  42. }
  43. #pragma mark - OverrideMethods
  44. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  45. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  46. RQCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  47. return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView];
  48. }
  49. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  50. [cell bindViewModel:object];
  51. }
  52. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  53. RQCommonHeaderView *headerView = [RQCommonHeaderView headerViewWithTableView:tableView];
  54. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  55. if ([self.viewModel.dataSource[section] isKindOfClass:[RQExciseExplainHeaderGroupViewModel class]]) {
  56. headerView = [RQExerciseExplainHeaderView headerViewWithTableView:tableView];
  57. }else if ([self.viewModel.dataSource[section] isKindOfClass:[NYExerciseTestingCentreGroupViewModel class]]) {
  58. RQExerciseExplainHeaderView *myheaderView = [RQExerciseExplainHeaderView headerViewWithTableView:tableView];
  59. if(groupViewModel.itemViewModels.count){
  60. RQCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[0];
  61. myheaderView.myTitleLabel.text = ((RQExerciseAnswerItemViewModel*)itemViewModel).ydtJSModel.fir_tilte;
  62. }
  63. headerView = myheaderView;
  64. }
  65. [headerView bindViewModel:groupViewModel];
  66. return headerView;
  67. }
  68. #pragma mark - JXPagerSmoothViewListViewDelegate
  69. - (UIView *)listView {
  70. return self.view;
  71. }
  72. - (UIScrollView *)listScrollView {
  73. return self.tableView;
  74. }
  75. @end