// // RQTestQuestionsViewController.m // JSJP // // Created by 张嵘 on 2021/8/12. // #import "RQTestQuestionsViewController.h" @interface RQTestQuestionsViewController () /// viewModel @property (nonatomic, readonly, strong) RQTestQuestionsViewModel *viewModel; @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView); @end @implementation RQTestQuestionsViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; [self updateFrame]; } - (void)updateFrame { 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 ); self.tableView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, height); } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { @weakify(self) self.tableView.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR; // RQ_Exercise_Module.currrentExerciseModel = self.viewModel.exerciseModel; [[[[RACObserve(RQ_AD_MANAGER, bannerIsShow) deliverOnMainThread] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) { @strongify(self) [self updateFrame]; }]; } #pragma mark - OverrideMethods - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; RQCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row]; return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView]; } - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { [cell bindViewModel:object]; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { RQCommonHeaderView *headerView = [RQCommonHeaderView headerViewWithTableView:tableView]; RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section]; if ([self.viewModel.dataSource[section] isKindOfClass:[RQExciseExplainHeaderGroupViewModel class]]) { headerView = [RQExerciseExplainHeaderView headerViewWithTableView:tableView]; }else if ([self.viewModel.dataSource[section] isKindOfClass:[NYExerciseTestingCentreGroupViewModel class]]) { RQExerciseExplainHeaderView *myheaderView = [RQExerciseExplainHeaderView headerViewWithTableView:tableView]; if(groupViewModel.itemViewModels.count){ RQCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[0]; myheaderView.myTitleLabel.text = ((RQExerciseAnswerItemViewModel*)itemViewModel).ydtJSModel.fir_tilte; } headerView = myheaderView; } [headerView bindViewModel:groupViewModel]; return headerView; } #pragma mark - JXPagerSmoothViewListViewDelegate - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { return self.tableView; } @end