// // PBMateralTableViewCell.m // IphoneBIMe // // Created by ZJF on 2022/9/4. // Copyright © 2022 ProBIM. All rights reserved. // #import "PBMateralTableViewCell.h" #import "PBSiteMechanicalModel.h" #import "PBSchedulesElementTableViewCell.h" #import "PBArtifactsInfoModel.h" #define maxTextCount 200 static NSString *const CellID = @"CellID"; @interface PBMateralTableViewCell() @property (nonatomic, weak) UILabel *taskNameL; //材料1 @property (nonatomic, weak) UILabel *chooseTaskL; //所选材料类型 @property (nonatomic, weak) UITableView *tableView; //部位 @property (nonatomic, weak) UITextField *specificationTF; //规格 @property (nonatomic, weak) UITextField *materialUnitTF; //单位 @property (nonatomic, weak) UILabel *totalNumL;//材料总量 @property (nonatomic, weak) UITextField *approachTF; //当日进厂量 @property (nonatomic, weak) UILabel *addupNumL; //累计进厂量 @property (nonatomic, weak) UITextView *textView;//生产情况 @property (nonatomic, weak) UILabel *arrivalTimePrL;//预计进场时间 @property (nonatomic, weak) UITextView *remarktextView;// 备注 @property (nonatomic, weak) UILabel *promptL; @property (nonatomic, weak) UILabel *prompt1L; //@property (nonatomic, strong) UIToolbar *kbToolbar; @property (nonatomic, strong) NSMutableArray *elements; @end @implementation PBMateralTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupUI]; } return self; } - (void)setupUI { UIButton *deleteBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"delete_task"]]; [deleteBtn addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:deleteBtn]; [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(6); make.left.equalTo(self.contentView).offset(12); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; UILabel *taskNameL = [UILabel z_labelWithText:@"人员1" Color:[UIColor z_colorWithR:95 G:158 B:249] isBold:YES Font:14]; [self.contentView addSubview:taskNameL]; [taskNameL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(deleteBtn); make.left.equalTo(deleteBtn.mas_right).offset(8); }]; UIButton *chooseTask = [[UIButton alloc] init]; [chooseTask addTarget:self action:@selector(choosetype) forControlEvents:UIControlEventTouchUpInside]; chooseTask.layer.cornerRadius = 4; chooseTask.layer.borderWidth = 1.f; chooseTask.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; [self.contentView addSubview:chooseTask]; [chooseTask mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(deleteBtn.mas_bottom).offset(6); make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.height.equalTo(@44); }]; UILabel *chooseTaskL = [UILabel z_labelWithText:@"请选择" Color:[UIColor z_colorWithR:174 G:174 B:174] isBold:NO Font:14]; [self.contentView addSubview:chooseTaskL]; [chooseTaskL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(chooseTask).offset(12); make.right.equalTo(chooseTask).offset(-44); make.centerY.equalTo(chooseTask); }]; UIImageView *chooseImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chooseTask_icon"]]; [self.contentView addSubview:chooseImageV]; [chooseImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(chooseTask).offset(18); make.right.equalTo(chooseTask).offset(-14); make.size.mas_equalTo(CGSizeMake(12, 10)); }]; UILabel *typeL = [UILabel z_labelWithText:@"部位" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:typeL]; [typeL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(chooseTask.mas_bottom).offset(16); make.left.equalTo(chooseTask); make.height.equalTo(@16); }]; UIButton *addPart = [UIButton z_bgImageButton:[UIImage imageNamed:@"addPart_btn"]]; [addPart addTarget:self action:@selector(addPart) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:addPart]; [addPart mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(typeL.mas_bottom).offset(6); make.left.right.height.equalTo(chooseTask); }]; UITableView *tableView = [[UITableView alloc] init]; tableView.dataSource = self; tableView.delegate = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // tableView.showsVerticalScrollIndicator = NO; tableView.rowHeight = 44.f; [tableView registerClass:[PBSchedulesElementTableViewCell class] forCellReuseIdentifier:CellID]; [self.contentView addSubview:tableView]; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(addPart.mas_bottom).offset(6); make.left.right.equalTo(chooseTask); make.height.equalTo(@100); }]; UILabel *specificationL = [UILabel z_labelWithText:@"规格" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:specificationL]; [specificationL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(tableView.mas_bottom).offset(16); make.left.equalTo(chooseTask); make.height.equalTo(@16); }]; UITextField *specificationTF = [[UITextField alloc] init]; specificationTF.placeholder = @"请输入..."; specificationTF.textAlignment= NSTextAlignmentLeft; specificationTF.textColor = PBColor(40, 58, 79); specificationTF.font = [UIFont fontWithName:Coarse size:14.0]; specificationTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; specificationTF.delegate = self; specificationTF.layer.cornerRadius = 4; specificationTF.layer.borderWidth = 1.f; specificationTF.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; specificationTF.leftViewMode = UITextFieldViewModeAlways; specificationTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 44)]; [self.contentView addSubview:specificationTF]; [specificationTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(specificationL.mas_bottom).offset(6); make.left.right.height.equalTo(chooseTask); }]; UILabel *materialUnitL = [UILabel z_labelWithText:@"单位" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:materialUnitL]; [materialUnitL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(specificationTF.mas_bottom).offset(16); make.left.equalTo(chooseTask); make.height.equalTo(@16); }]; UITextField *materialUnitTF = [[UITextField alloc] init]; materialUnitTF.placeholder = @"请输入..."; materialUnitTF.textAlignment= NSTextAlignmentLeft; materialUnitTF.textColor = PBColor(40, 58, 79); materialUnitTF.font = [UIFont fontWithName:Coarse size:14.0]; materialUnitTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; materialUnitTF.delegate = self; materialUnitTF.layer.cornerRadius = 4; materialUnitTF.layer.borderWidth = 1.f; materialUnitTF.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; materialUnitTF.leftViewMode = UITextFieldViewModeAlways; materialUnitTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 44)]; [self.contentView addSubview:materialUnitTF]; [materialUnitTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(materialUnitL.mas_bottom).offset(6); make.left.right.height.equalTo(chooseTask); }]; UILabel *totalL = [UILabel z_labelWithText:@"材料总量:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:totalL]; [totalL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(materialUnitTF.mas_bottom).offset(16); make.left.height.equalTo(chooseTask); }]; UILabel *totalNumL = [UILabel z_labelWithText:@" 223" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:14]; totalNumL.backgroundColor = PBColor(243, 243, 244); [totalNumL circleViewWithRadius:4]; [self.contentView addSubview:totalNumL]; [totalNumL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(totalL); make.left.equalTo(self.contentView).offset(100); make.right.height.equalTo(chooseTask); }]; UILabel *approachL = [UILabel z_labelWithText:@"当日进场量:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:approachL]; [approachL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(totalNumL.mas_bottom).offset(16); make.left.height.equalTo(chooseTask); }]; UITextField *approachTF = [[UITextField alloc] init]; approachTF.placeholder = @"请输入..."; approachTF.textAlignment= NSTextAlignmentLeft; approachTF.textColor = PBColor(40, 58, 79); approachTF.font = [UIFont fontWithName:Coarse size:14.0]; approachTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; approachTF.delegate = self; approachTF.layer.cornerRadius = 4; approachTF.layer.borderWidth = 1.f; approachTF.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; approachTF.leftViewMode = UITextFieldViewModeAlways; approachTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 44)]; [self.contentView addSubview:approachTF]; [approachTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(approachL); make.left.equalTo(self.contentView).offset(100); make.right.height.equalTo(chooseTask); }]; UILabel *addupL = [UILabel z_labelWithText:@"累计进场量:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:addupL]; [addupL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(approachTF.mas_bottom).offset(16); make.left.height.equalTo(chooseTask); }]; UILabel *addupNumL = [UILabel z_labelWithText:@" 2123" Color:[UIColor z_colorWithR:40 G:58 B:79] isBold:YES Font:16]; addupNumL.backgroundColor = PBColor(243, 243, 244); [addupNumL circleViewWithRadius:4]; [self.contentView addSubview:addupNumL]; [addupNumL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(addupL); make.left.equalTo(self.contentView).offset(100); make.right.height.equalTo(chooseTask); }]; UILabel *generationL = [UILabel z_labelWithText:@"生产情况:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:generationL]; [generationL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(addupNumL.mas_bottom).offset(16); make.left.height.equalTo(chooseTask); }]; UIView *bgView = [[UIView alloc] init]; bgView.backgroundColor = [UIColor whiteColor]; [self.contentView addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(generationL); make.left.equalTo(self.contentView).offset(100); make.right.equalTo(chooseTask); make.height.equalTo(@132); }]; bgView.layer.cornerRadius = 4; bgView.layer.borderWidth = 1; bgView.layer.borderColor = PBColor(108, 108, 108).CGColor; UITextView *textView = [[UITextView alloc] init]; textView.textColor= PBColor(40, 58, 79); textView.font = [UIFont boldSystemFontOfSize:14]; textView.delegate = self; [bgView addSubview:textView]; [textView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(bgView).offset(10); make.left.equalTo(bgView).offset(10); make.right.equalTo(bgView).offset(-10); make.bottom.equalTo(bgView).offset(-10); }]; // textView.inputAccessoryView = self.kbToolbar; UILabel *promptL= [UILabel z_labelWithText:@"请输入..." Color:PBColor(174, 174, 174) isBold:YES Font:14]; [bgView addSubview:promptL]; [promptL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(textView).offset(8); make.left.equalTo(textView).offset(6); }]; UILabel *arrivalTimeL = [UILabel z_labelWithText:@"预计到场:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:arrivalTimeL]; [arrivalTimeL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(bgView.mas_bottom).offset(16); make.left.height.equalTo(chooseTask); }]; UIButton *arrivalTime = [[UIButton alloc] init]; [arrivalTime addTarget:self action:@selector(chooseTime) forControlEvents:UIControlEventTouchUpInside]; arrivalTime.layer.cornerRadius = 4; arrivalTime.layer.borderWidth = 1.f; arrivalTime.layer.borderColor = [[UIColor z_colorWithR:108 G:108 B:108] CGColor]; [self.contentView addSubview:arrivalTime]; [arrivalTime mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(arrivalTimeL); make.left.equalTo(self.contentView).offset(100); make.right.equalTo(chooseTask); make.height.equalTo(@44); }]; UILabel *arrivalTimePrL = [UILabel z_labelWithText:@"请选择" Color:[UIColor z_colorWithR:174 G:174 B:174] isBold:NO Font:14]; [self.contentView addSubview:arrivalTimePrL]; [arrivalTimePrL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(arrivalTime).offset(12); make.right.equalTo(arrivalTime).offset(-44); make.centerY.equalTo(arrivalTime); }]; UIImageView *timeImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"date_btn"]]; [self.contentView addSubview:timeImageV]; [timeImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(arrivalTime).offset(10); make.right.equalTo(arrivalTime).offset(-10); make.size.mas_equalTo(CGSizeMake(24, 24)); }]; UILabel *remarkL = [UILabel z_labelWithText:@"备注:" Color:[UIColor z_colorWithR:51 G:51 B:51] isBold:YES Font:14]; [self.contentView addSubview:remarkL]; [remarkL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(arrivalTimeL.mas_bottom).offset(16); make.left.height.equalTo(chooseTask); }]; UIView *remarkbgView = [[UIView alloc] init]; remarkbgView.backgroundColor = [UIColor whiteColor]; [self.contentView addSubview:remarkbgView]; [remarkbgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(remarkL); make.left.equalTo(self.contentView).offset(100); make.right.equalTo(chooseTask); make.bottom.equalTo(self.contentView).offset(-20); make.height.equalTo(@132); }]; remarkbgView.layer.cornerRadius = 4; remarkbgView.layer.borderWidth = 1; remarkbgView.layer.borderColor = PBColor(108, 108, 108).CGColor; UITextView *remarktextView = [[UITextView alloc] init]; remarktextView.textColor= PBColor(40, 58, 79); remarktextView.font = [UIFont boldSystemFontOfSize:14]; remarktextView.delegate = self; [remarkbgView addSubview:remarktextView]; [remarktextView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(remarkbgView).offset(10); make.left.equalTo(remarkbgView).offset(10); make.right.equalTo(remarkbgView).offset(-10); make.bottom.equalTo(remarkbgView).offset(-10); }]; // remarktextView.inputAccessoryView = self.kbToolbar; UILabel *prompt1L= [UILabel z_labelWithText:@"请输入..." Color:PBColor(174, 174, 174) isBold:YES Font:14]; [remarkbgView addSubview:prompt1L]; [prompt1L mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(remarktextView).offset(8); make.left.equalTo(remarktextView).offset(6); }]; // specificationTF.inputAccessoryView = self.kbToolbar; // materialUnitTF.inputAccessoryView = self.kbToolbar; // approachTF.inputAccessoryView = self.kbToolbar; self.taskNameL = taskNameL; self.chooseTaskL = chooseTaskL; self.tableView = tableView; self.specificationTF = specificationTF; self.materialUnitTF = materialUnitTF; self.totalNumL = totalNumL; self.approachTF = approachTF; self.addupNumL = addupNumL; self.textView = textView; self.arrivalTimePrL = arrivalTimePrL; self.remarktextView = remarktextView; self.promptL = promptL; self.prompt1L = prompt1L; } - (void)choosetype { if (self.ChooseTypeBlock) { self.ChooseTypeBlock(); } } - (void)chooseTime { if (self.ChooseTimeBlock) { self.ChooseTimeBlock(); } } - (void)addPart { if(self.AddElementBlock) { self.AddElementBlock(); } } - (void)deleteAction { if (self.DeleteBlock) { self.DeleteBlock(); } } - (void)setSiteMechanicalModel:(PBSiteMechanicalModel *)siteMechanicalModel { _siteMechanicalModel = siteMechanicalModel; if (siteMechanicalModel.MachineDetial_Name == nil) { self.chooseTaskL.textColor = PBColor(174, 174, 174); self.chooseTaskL.text = @"请选择"; }else { self.chooseTaskL.textColor = PBColor(51, 51, 51); self.chooseTaskL.text = siteMechanicalModel.MachineDetial_Name; } self.elements = siteMechanicalModel.elementList.mutableCopy; NSInteger tableH = 44 * self.elements.count; [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(tableH)); }]; [self.tableView reloadData]; self.specificationTF.text = siteMechanicalModel.MachineDetial_Size; self.materialUnitTF.text = siteMechanicalModel.MachineDetial_Unit; if (siteMechanicalModel.MachineDetial_Sum==nil){ siteMechanicalModel.MachineDetial_Sum = @""; } self.totalNumL.text = [NSString stringWithFormat:@" %@",siteMechanicalModel.MachineDetial_Sum]; self.approachTF.text = siteMechanicalModel.MachineDetial_Approcach; if (siteMechanicalModel.MachineDetial_Add==nil){ siteMechanicalModel.MachineDetial_Add = @""; } self.addupNumL.text = [NSString stringWithFormat:@" %@",siteMechanicalModel.MachineDetial_Add]; self.textView.text = siteMechanicalModel.MachineDetial_Product; if (self.textView.text.length == 0) { self.promptL.hidden = NO; }else { self.promptL.hidden = YES; } if (siteMechanicalModel.MachineDetial_Estimated == nil) { self.arrivalTimePrL.textColor = PBColor(174, 174, 174); self.arrivalTimePrL.text = @"请选择日期"; }else { self.arrivalTimePrL.textColor = PBColor(51, 51, 51); self.arrivalTimePrL.text = siteMechanicalModel.MachineDetial_Estimated; } self.remarktextView.text = siteMechanicalModel.MachineDetial_Remark; if (self.remarktextView.text.length == 0) { self.prompt1L.hidden = NO; }else { self.prompt1L.hidden = YES; } } -(void)setMaterialIndex:(NSInteger)materialIndex { _materialIndex = materialIndex; self.taskNameL.text = [NSString stringWithFormat:@"材料%zd",materialIndex]; } //- (UIToolbar *) kbToolbar { // if (_kbToolbar == nil) { // _kbToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 44)]; // UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(closeKeyboard)]; // _kbToolbar.items = @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], doneItem]; // } // return _kbToolbar; //} //- (void)closeKeyboard { // [self endEditing:YES]; //} #pragma mark - UITextFieldDelegate - (void)textFieldDidEndEditing:(UITextField *)textField{ if (textField == self.specificationTF) { self.siteMechanicalModel.MachineDetial_Size = textField.text; }else if (textField == self.materialUnitTF){ self.siteMechanicalModel.MachineDetial_Unit = textField.text; }else { self.siteMechanicalModel.MachineDetial_Approcach = textField.text; NSInteger approcach = [self.siteMechanicalModel.MachineDetial_Approcach integerValue]; NSInteger total = [self.siteMechanicalModel.MachineDetialAdd integerValue]; self.siteMechanicalModel.MachineDetial_Add = [NSString stringWithFormat:@"%zd",approcach + total]; self.addupNumL.text = [NSString stringWithFormat:@" %@", self.siteMechanicalModel.MachineDetial_Add]; } } #pragma mark - UITextViewDelegate - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { NSLog(@"%zd",textView.text.length); NSLog(@"===shouldChangeText"); UITextRange *selectedRange = [textView markedTextRange]; //获取高亮部分 UITextPosition *pos = [textView positionFromPosition:selectedRange.start offset:0]; //获取高亮部分内容 //NSString * selectedtext = [textView textInRange:selectedRange]; //如果有高亮且当前字数开始位置小于最大限制时允许输入 if (selectedRange && pos) { NSInteger startOffset = [textView offsetFromPosition:textView.beginningOfDocument toPosition:selectedRange.start]; NSInteger endOffset = [textView offsetFromPosition:textView.beginningOfDocument toPosition:selectedRange.end]; NSRange offsetRange = NSMakeRange(startOffset, endOffset - startOffset); if (offsetRange.location < maxTextCount) { return YES; } else{ return NO; } } NSString *comcatstr = [textView.text stringByReplacingCharactersInRange:range withString:text]; NSInteger caninputlen = maxTextCount - comcatstr.length; if (caninputlen >= 0){ return YES; }else{ NSInteger len = text.length + caninputlen; //防止当text.length + caninputlen < 0时,使得rg.length为一个非法最大正数出错 NSRange rg = {0,MAX(len,0)}; if (rg.length > 0){ NSString *s = @""; //判断是否只普通的字符或asc码(对于中文和表情返回NO) BOOL asc = [text canBeConvertedToEncoding:NSASCIIStringEncoding]; if (asc) { s = [text substringWithRange:rg];//因为是ascii码直接取就可以了不会错 }else{ __block NSInteger idx = 0; __block NSString *trimString = @"";//截取出的字串 //使用字符串遍历,这个方法能准确知道每个emoji是占一个unicode还是两个 [text enumerateSubstringsInRange:NSMakeRange(0, [text length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock: ^(NSString* substring, NSRange substringRange, NSRange enclosingRange, BOOL* stop) { if (idx >= rg.length) { *stop = YES; //取出所需要就break,提高效率 return ; } trimString = [trimString stringByAppendingString:substring]; idx++; }]; s = trimString; } //rang是指从当前光标处进行替换处理(注意如果执行此句后面返回的是YES会触发didchange事件) [textView setText:[textView.text stringByReplacingCharactersInRange:range withString:s]]; //既然是超出部分截取了,哪一定是最大限制了。 // self.textLengthL.text = [NSString stringWithFormat:@"%d/%ld",0,(long)maxTextCount]; } return NO; } } - (void)textViewDidChange:(UITextView *)textView{ if (textView == self.textView) { if (textView.text.length == 0) { self.promptL.hidden = NO; }else { self.promptL.hidden = YES; } }else { if (textView.text.length == 0) { self.prompt1L.hidden = NO; }else { self.prompt1L.hidden = YES; } } NSLog(@"===DidChangeText"); UITextRange *selectedRange = [textView markedTextRange]; //获取高亮部分 UITextPosition *pos = [textView positionFromPosition:selectedRange.start offset:0]; //如果在变化中是高亮部分在变,就不要计算字符了 if (selectedRange && pos) { return; } NSString *nsTextContent = textView.text; NSInteger existTextNum = nsTextContent.length; if (existTextNum > maxTextCount){ //截取到最大位置的字符(由于超出截部分在should时被处理了所在这里这了提高效率不再判断) NSString *s = [nsTextContent substringToIndex:maxTextCount]; [textView setText:s]; } if (textView == self.textView) { self.siteMechanicalModel.MachineDetial_Product = textView.text; }else { self.siteMechanicalModel.MachineDetial_Remark = textView.text; } } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.elements.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PBSchedulesElementTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath]; PBArtifactsInfoModel *model = self.elements[indexPath.row]; cell.artifactsModel = model; cell.DeleteBlock = ^{ [self.elements removeObjectAtIndex:indexPath.row]; [self updateTableViewWithDate:self.elements.copy]; }; return cell; } - (void)updateTableViewWithDate:(NSArray *)element { // self.siteMechanicalModel.elementList = element; // NSInteger tableH = 44 * self.siteMechanicalModel.elementList.count; // [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) { // make.height.equalTo(@(tableH)); // }]; // [self.tableView reloadData]; if (self.DeleteElementBlock) { self.DeleteElementBlock(element); } } - (NSMutableArray *)elements { if (_elements == nil) { _elements = [[NSMutableArray alloc] init]; } return _elements; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end