// // RQTestQuestionsViewController.m // SDJK // // Created by 张嵘 on 2021/8/12. // #import "RQTestQuestionsViewController.h" @interface RQTestQuestionsViewController () /// viewModel @property (nonatomic, readonly, strong) RQTestQuestionsViewModel *viewModel; @end @implementation RQTestQuestionsViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [RQ_MUSIC_MANAGER rq_cancelStreamer]; } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { [RQ_MUSIC_MANAGER rq_cancelStreamer]; self.tableView.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR; RQ_Exercise_Module.currrentExerciseModel = self.viewModel.exerciseModel; [[[RQNotificationCenter rac_addObserverForName:RQQuestionReloadNotification object:nil] deliverOnMainThread] subscribeNext:^(NSNotification * note) { RQExerciseModel *exerciseModel = note.object[RQQuestionReloadExerciseModelKey]; if (self.viewModel.exerciseModel.issue == exerciseModel.issue) { self.viewModel.exerciseModel = exerciseModel; [self reloadData]; } }]; } #pragma mark - OverrideMethods /// 配置tableView的区域 - (UIEdgeInsets)contentInset { return UIEdgeInsetsMake(0, 0, RQ_APPLICATION_TOP_BAR_HEIGHT + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + 65 + 49, 0); } - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { switch (indexPath.section) { case 0: { RQExerciseQuestionCell *cell = [RQExerciseQuestionCell cellWithTableView:tableView]; return cell; } case 1: { RQExerciseOptionCell *cell = [RQExerciseOptionCell cellWithTableView:tableView]; return cell; } case 2 : { RQExerciseAnswerCell *cell = [RQExerciseAnswerCell cellWithTableView:tableView]; return cell; } case 3 : { RQExerciseOptionSureBtnCell *cell = [RQExerciseOptionSureBtnCell cellWithTableView:tableView]; return cell; } case 4 : { RQExerciseToolBarCell *cell = [RQExerciseToolBarCell cellWithTableView:tableView]; return cell; } case 5 : { RQExerciseExamToolBarCell *cell = [RQExerciseExamToolBarCell cellWithTableView:tableView]; return cell; } default: return [super tableView:tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; } } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { switch (indexPath.section) { case 0: { RQExerciseQuestionCell *exerciseQuestionCell = (RQExerciseQuestionCell *)cell; [exerciseQuestionCell bindViewModel:object]; break; } case 1: { RQExerciseOptionCell *exerciseOptionCell = (RQExerciseOptionCell *)cell; [exerciseOptionCell bindViewModel:object]; break; } case 2: { RQExerciseAnswerCell *exerciseAnswerCell = (RQExerciseAnswerCell *)cell; [exerciseAnswerCell bindViewModel:object]; break; } case 3: { RQExerciseOptionSureBtnCell *exerciseOptionSureBtnCell = (RQExerciseOptionSureBtnCell *)cell; [exerciseOptionSureBtnCell bindViewModel:object]; break; } case 4: { RQExerciseToolBarCell *exerciseToolBarCell = (RQExerciseToolBarCell *)cell; [exerciseToolBarCell bindViewModel:object]; break; } case 5: { RQExerciseExamToolBarCell *exerciseExamToolBarCell = (RQExerciseExamToolBarCell *)cell; [exerciseExamToolBarCell bindViewModel:object]; break; } default: [super configureCell:cell atIndexPath:indexPath withObject:object]; break; } } @end