NYFailSpecialExerciseDetailsCell.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // NYFailSpecialExerciseDetailsCell.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/12/12.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYFailSpecialExerciseDetailsCell.h"
  9. @interface NYFailSpecialExerciseDetailsCell ()
  10. @property (nonatomic, readwrite, strong) NYFailSpecialExerciseDetailItemModel *viewModel;
  11. @end
  12. @implementation NYFailSpecialExerciseDetailsCell
  13. #pragma mark - PublicMethods
  14. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  15. static NSString *ID = @"NYFailSpecialExerciseDetailsCell";
  16. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  17. NYFailSpecialExerciseDetailsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  18. if (!cell) cell = [self rq_viewFromXib];
  19. return cell;
  20. }
  21. - (void)bindViewModel:(NYFailSpecialExerciseDetailItemModel *)viewModel {
  22. self.viewModel = viewModel;
  23. if(viewModel.dataModel.showType.intValue == 1){
  24. self.scoreStr_label.text = [NSString stringWithFormat:@"%zd分",viewModel.dataModel.score];
  25. CGFloat yOffset = 0; // 初始偏移量
  26. CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整)
  27. int bi = 0;
  28. for (int i= 0; i<viewModel.dataModel.question_array.count; i++) {
  29. NSString *title_str = [NSString stringWithFormat:@"%zd.%@",i+1,viewModel.dataModel.question_array[i]];
  30. // 从 XIB 加载 NYFailItemPointCellView
  31. NYFailItemPointCellView *cellView = [self.tbList_view viewWithTag:99+i];
  32. cellView.hidden = NO;
  33. CGSize str_size = [title_str rq_sizeWithFont:cellView.content_label.font limitWidth:cellView.content_label.width];
  34. if(str_size.height>cellHeight){
  35. cellHeight = str_size.height + 12.f;
  36. }
  37. cellView.frame = CGRectMake(0, yOffset, RQ_SCREEN_WIDTH-22*2, cellHeight);
  38. cellView.content_label.text = title_str;
  39. // 调整偏移量
  40. yOffset += cellHeight;
  41. bi = i+1;
  42. }
  43. for (int ci=bi; ci<30; ci++) {
  44. NYFailItemPointCellView *cellView = [self.tbList_view viewWithTag:99+ci];
  45. cellView.hidden = YES;
  46. }
  47. }
  48. // RAC(self.scoreStr_label, text) = [[/*RACObserve(viewModel.dataModel, s) deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal];*/
  49. }
  50. - (IBAction)submit_clickdo:(UIButton *)sender {
  51. NSString *questionIds = self.viewModel.dataModel.questionIds;
  52. NSArray *arr = [[RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Error_Special_List questionIds:questionIds].rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  53. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  54. }].toArray;
  55. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  56. RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
  57. RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
  58. RQHomeSubPageTypeKey : @(RQHomeSubPageType_SequentialPractice),
  59. RQViewModelIDKey : @"标题",
  60. RQExerciseTypeKey : @(RQExerciseType_Error_Special_List),
  61. RQViewModelUtilKey : arr,
  62. }];
  63. [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
  64. }
  65. #pragma mark - SystemMethods
  66. - (void)awakeFromNib {
  67. [super awakeFromNib];
  68. [self initTbList_view];
  69. }
  70. - (void)initTbList_view{
  71. self.vm_bm_imageView.image = [UIImage rq_resizableImage:@"blue_jb_bg"];
  72. // 初始化按钮
  73. CGFloat yOffset = 0; // 初始偏移量
  74. CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整)
  75. for (int i= 0; i<30; i++) {
  76. // 从 XIB 加载 NYFailItemPointCellView
  77. NYFailItemPointCellView *cellView = [[NYFailItemPointCellView alloc] initWithFrame:CGRectMake(0, yOffset, RQ_SCREEN_WIDTH-22*2, cellHeight)];
  78. //[[NSBundle mainBundle] loadNibNamed:@"NYFailItemPointCellView" owner:nil options:nil].firstObject;
  79. cellView.tag = 99+i;
  80. cellView.hidden = YES;
  81. // 添加到 tbList_view
  82. [self.tbList_view addSubview:cellView];
  83. // 调整偏移量
  84. yOffset += cellHeight;
  85. }
  86. }
  87. @end