// // NYFailSpecialExerciseDetailsCell01.m // jiaPei // // Created by Ning.ge on 2024/12/17. // Copyright © 2024 JCZ. All rights reserved. // #import "NYFailSpecialExerciseDetailsCell01.h" @interface NYFailSpecialExerciseDetailsCell01 () @property (nonatomic, readwrite, strong) NYFailSpecialExerciseDetailItemModel *viewModel; @end @implementation NYFailSpecialExerciseDetailsCell01 #pragma mark - PublicMethods + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"NYFailSpecialExerciseDetailsCell01"; [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID]; NYFailSpecialExerciseDetailsCell01 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; if (!cell) cell = [self rq_viewFromXib]; return cell; } - (void)bindViewModel:(NYFailSpecialExerciseDetailItemModel *)viewModel { @weakify(self) self.viewModel = viewModel; if([viewModel.title isEqualToString:@"zhouqi"]|| [viewModel.title isEqualToString:@"tianqi"]){ self.scoreStr_label.attributedText = [self getAttributedString:viewModel.dataModel.title color:UIColorHex(0xFF6714)]; }else{ self.scoreStr_label.text = viewModel.dataModel.title; } self.vw_left_label.text = viewModel.itemPointTitle; __block CGFloat yOffset = 0; // 初始偏移量 __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) int bi = 0; CGFloat imgW = (RQ_SCREEN_WIDTH-22*2); self.itop_view.hidden = YES; if(viewModel.dataModel.con.count>0){//手势 // 在方法内定义串行队列 dispatch_queue_t serialQueue = dispatch_queue_create("com.yourapp.imageLoadingQueue", DISPATCH_QUEUE_SERIAL); self.vw_left_view.hidden = YES; self.itop_view.hidden = NO; self.scoreStr_label.text = viewModel.dataModel.mainTit; __block CGFloat itop_yOffset = 0; // 初始偏移量 __block CGFloat itop_cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) int itop_bi = 0; for (int i= 0; iitop_cellHeight){ itop_cellHeight = str_size.height + 12.f; } cellView.content_label.attributedText = [self getAttributedString:con.title color:UIColorHex(0xFF6714)]; NSString *img_url = con.image; if(![img_url isEqualToString:@""]){ self.itop_view.frame = CGRectMake(0, 0, imgW, viewModel.dataModel.iviewH+viewModel.dataModel.imgsH); UIImageView *image_view = [self.itop_view viewWithTag:79+i]; __block CGSize imageSize = CGSizeMake(imgW,cellHeight); dispatch_async(serialQueue, ^{ // 处理耗时操作的代码块... imageSize = [UIImage getImageSizeWithURL:img_url]; //通知主线程刷新 dispatch_async(dispatch_get_main_queue(), ^{ cellView.frame = CGRectMake(0, itop_yOffset, RQ_SCREEN_WIDTH-22*2, itop_cellHeight); itop_yOffset +=itop_cellHeight; //回调或者说是通知主线程刷新, if (imageSize.width == 0 || imageSize.height == 0) { cellHeight = imgW * (175.f / 345.f); } else { cellHeight = imgW * (imageSize.height / imageSize.width); } image_view.frame = CGRectMake(0, itop_yOffset, imgW, cellHeight); // 调整偏移量 itop_yOffset += cellHeight+10*(i+1); }); }); [image_view sd_setImageWithURL:[NSURL URLWithString:img_url]]; image_view.hidden = NO; bi = i+1; itop_bi = i+1; }else{ dispatch_async(serialQueue, ^{ //通知主线程刷新 dispatch_async(dispatch_get_main_queue(), ^{ cellView.frame = CGRectMake(0, itop_yOffset, RQ_SCREEN_WIDTH-22*2, itop_cellHeight); itop_yOffset +=itop_cellHeight; }); }); itop_bi = i+1; } } if(con.questions.count>0){//二层子集 for (int z= 0; zitop_cellHeight){ itop_cellHeight = str_size.height + 12.f; } cellView.content_label.attributedText = [self getAttributedString:subTitle_str color:UIColorHex(0xFF6714)]; UIImageView *image_view = [self.itop_view viewWithTag:79+i+z+1]; __block CGSize imageSize = CGSizeMake(imgW,cellHeight); dispatch_async(serialQueue, ^{ // 处理耗时操作的代码块... imageSize = [UIImage getImageSizeWithURL:img_url]; //通知主线程刷新 dispatch_async(dispatch_get_main_queue(), ^{ cellView.frame = CGRectMake(0, itop_yOffset, RQ_SCREEN_WIDTH-22*2, itop_cellHeight); itop_yOffset +=itop_cellHeight; //回调或者说是通知主线程刷新, if (imageSize.width == 0 || imageSize.height == 0) { cellHeight = imgW * (175.f / 345.f); } else { cellHeight = imgW * (imageSize.height / imageSize.width); } image_view.frame = CGRectMake(0, itop_yOffset, imgW, cellHeight); // 调整偏移量 itop_yOffset += cellHeight+10*(z+1); }); }); [image_view sd_setImageWithURL:[NSURL URLWithString:img_url]]; image_view.hidden = NO; bi += z+1; itop_bi += z+1; } } } } for (int ci=itop_bi; ci<10; ci++) { NYFailItemPointCellView *cellView = [self.itop_view viewWithTag:19+ci]; cellView.hidden = YES; } for (int ci=bi; ci<10; ci++) { UIImageView *image_view = [self.itop_view viewWithTag:79+ci]; image_view.hidden = YES; } } if(viewModel.dataModel.tagquestions.count>0){ self.vw_left_view.hidden = YES; self.itop_view.hidden = NO; self.itop_view.frame = CGRectMake(0, 0, imgW, viewModel.dataModel.iviewH); CGFloat tagitop_yOffset = 10; // 初始偏移量 CGFloat tagtop_cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) int tagitop_bi = 0; int tagitop_bicc = 0; int tagitop_biccc = 0; for (int i= 0; itagtop_cellHeight){ tagtop_cellHeight = str_size.height + 12.f; } cellView.frame = CGRectMake(0, tagitop_yOffset, RQ_SCREEN_WIDTH-22*2, tagtop_cellHeight); cellView.content_label.attributedText = [self getAttributedString:title_str color:UIColorHex(0xFF6714)]; // 调整偏移量 tagitop_yOffset += tagtop_cellHeight; if(textItem.quesItem.count>0){ CGFloat ab_H = 20.f; for (int t= 0; t0){ for (int i= 0; i0){ self.vw_left_view.hidden = YES; self.itop_view.hidden = NO; self.itop_view.frame = CGRectMake(0, 0, imgW, viewModel.dataModel.iviewH); yOffset = CGRectGetMaxY(self.itop_view.frame) +10.f; CGFloat fitop_yOffset = 0; // 初始偏移量 CGFloat fitop_cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) int fitop_bi = 0; int fitop_bicc = 0; for (int i= 0; ifitop_cellHeight){ fitop_cellHeight = str_size.height + 12.f; } cellView.frame = CGRectMake(0, fitop_yOffset, RQ_SCREEN_WIDTH-22*2, fitop_cellHeight); cellView.content_label.attributedText = [self getAttributedString:title_str color:UIColorHex(0xFF6714)]; // 调整偏移量 fitop_yOffset += fitop_cellHeight; fitop_bi = i+1; if(textItem.quesItem.count>0){ CGFloat ab_H = 20.f; for (int z= 0; z0){ self.itop_view.hidden = NO; self.itop_view.frame = CGRectMake(0, 0, imgW, viewModel.dataModel.iviewH); yOffset = CGRectGetMaxY(self.itop_view.frame) +10.f; CGFloat itop_yOffset = 0; // 初始偏移量 CGFloat itop_cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整) int itop_bi = 0; int itop_bicc = 0; for (int i= 0; iitop_cellHeight){ itop_cellHeight = str_size.height + 12.f; } cellView.frame = CGRectMake(0, itop_yOffset, RQ_SCREEN_WIDTH-22*2, itop_cellHeight); cellView.content_label.attributedText = [self getAttributedString:title_str color:UIColorHex(0xFF6714)]; // 调整偏移量 itop_yOffset += itop_cellHeight; itop_bi = i+1; if(textItem.quesItem.count>0){ CGFloat ab_H = 20.f; for (int z= 0; z0){ for (int i= 0; i *replacements = [NSMutableArray array]; // 匹配 [ ] 中的内容 NSArray *matches = [regex matchesInString:str options:0 range:NSMakeRange(0, str.length)]; for (NSTextCheckingResult *match in matches) { if (match.numberOfRanges > 1) { // 提取 [ ] 内部的内容 NSRange innerRange = [match rangeAtIndex:1]; NSString *matchedText = [str substringWithRange:innerRange]; // 保存替换内容和范围 [replacements addObject:@{ @"text": matchedText, @"range": [NSValue valueWithRange:match.range] }]; } } // 创建可变字符串以进行替换 NSMutableString *updatedString = [NSMutableString stringWithString:str]; NSMutableArray *highlightedRanges = [NSMutableArray array]; NSInteger offset = 0; for (NSDictionary *replacement in replacements) { NSString *text = replacement[@"text"]; NSRange range = [replacement[@"range"] rangeValue]; // 调整范围以匹配当前字符串的变化 range.location += offset; // 替换 [ ] 为其内部内容 [updatedString replaceCharactersInRange:range withString:text]; // 记录调整后的范围 NSRange adjustedRange = NSMakeRange(range.location, text.length); [highlightedRanges addObject:[NSValue valueWithRange:adjustedRange]]; // 更新偏移量 offset += (text.length - range.length); } // 创建 NSMutableAttributedString NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:updatedString]; // 设置高亮颜色(黄色) for (NSValue *rangeValue in highlightedRanges) { [attributedString addAttribute:NSForegroundColorAttributeName value:color range:rangeValue.rangeValue]; } return attributedString; } - (IBAction)submit_clickdo:(UIButton *)sender { NSString *questionIds = self.viewModel.dataModel.questionIds; NSArray *arr = [[RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Error_Special_List questionIds:questionIds].rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) { return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel]; }].toArray; RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{ RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType), RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject), RQHomeSubPageTypeKey : @(RQHomeSubPageType_SequentialPractice), RQViewModelIDKey : @"标题", RQExerciseTypeKey : @(RQExerciseType_Error_Special_List), RQViewModelUtilKey : arr, }]; [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES]; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; [self initTbList_view]; } - (void)initTbList_view{ self.vm_bm_imageView.image = [UIImage rq_resizableImage:@"blue_jb_bg"]; UIView *itop_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH-22*2, 20)]; itop_view.backgroundColor = UIColor.whiteColor; itop_view.layer.cornerRadius = 5.f; itop_view.layer.masksToBounds = YES; itop_view.hidden = YES; [self.item_view addSubview:itop_view]; self.itop_view = itop_view; //10 + 10 for (int i= 0; i<10; i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:15.f]; btn.backgroundColor = UIColorHex(0xC1D7FF); btn.layer.cornerRadius = 5.f; btn.layer.masksToBounds = YES; btn.tag = 29+i; btn.hidden = YES; [self.itop_view addSubview:btn]; } for (int i= 0; i<10; i++) { NYFailItemPointCellView *cellView = [[NYFailItemPointCellView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH-22*2, 0)]; cellView.tag = 19+i; cellView.hidden = YES; [self.itop_view addSubview:cellView]; } for (int i= 0; i<10; i++) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, RQ_SCREEN_WIDTH-22*2, 0)]; label.font = [UIFont systemFontOfSize:11.f]; label.textColor = UIColorHex(0x5C6066); label.tag = 59+i; label.hidden = YES; [self.itop_view addSubview:label]; } for (int i= 0; i<10; i++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH-22*2, 0)]; imageView.tag = 79+i; imageView.hidden = YES; [self.itop_view addSubview:imageView]; } // 初始化按钮 CGFloat yOffset = 0; // 初始偏移量 CGFloat cellHeight = 1.f; // 每个 Cell 的高度(根据实际设计调整) for (int i= 0; i<10; i++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, yOffset, RQ_SCREEN_WIDTH-22*2, cellHeight)]; imageView.tag = 99+i; imageView.hidden = YES; // 添加到 tbList_view [self.item_view addSubview:imageView]; // 调整偏移量 yOffset += cellHeight; } } @end