// // PBListTableViewCell.m // IphoneBIMe // // Created by zjf on 2020/8/18. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBListTableViewCell.h" #import "PBExamineAddModel.h" #import "PBListDataTableViewCell.h" #import "PBArtifactsInfoModel.h" static NSString *const cellID = @"CellID"; @interface PBListTableViewCell() @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, weak) UILabel *titleL; @property (nonatomic, weak) UILabel *descL; @property (nonatomic, weak) UILabel *promteL; @property (nonatomic, weak) UIButton *selectBtn; @end @implementation PBListTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupUI]; } return self; } - (void)setupUI { UILabel *titleL = [UILabel z_labelWithText:@"" Color:PromptColor isBold:NO Font:14]; titleL.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(10); make.left.equalTo(self.contentView).offset(10); make.right.equalTo(self.contentView).offset(-10); make.height.equalTo(@20); }]; // UILabel *descL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:18]; // descL.numberOfLines = 0; // descL.textAlignment = NSTextAlignmentCenter; // [self.contentView addSubview:descL]; // [descL mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(titleL.mas_bottom).offset(16); // make.left.right.equalTo(titleL); // make.bottom.equalTo(self.contentView).offset(-16); // make.height.mas_greaterThanOrEqualTo(25); // }]; UILabel *promteL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:TitleFontSize]; [self.contentView addSubview:promteL]; [promteL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleL.mas_bottom).offset(10); make.centerX.equalTo(titleL); make.height.equalTo(@25); }]; self.tableView = [[UITableView alloc] init]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.bounces = NO; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.tableView registerClass:[PBListDataTableViewCell class] forCellReuseIdentifier:cellID]; [self.contentView addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleL.mas_bottom).offset(14); make.left.right.bottom.equalTo(self.contentView); make.height.equalTo(@1); // make.bottom.equalTo(self.contentView).offset(-25); }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.equalTo(self); make.bottom.equalTo(self.tableView.mas_bottom).offset(25); }]; UIButton *selectBtn = [[UIButton alloc] init]; [selectBtn addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:selectBtn]; [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.equalTo(self.contentView); make.right.equalTo(self.contentView).offset(-100); }]; self.titleL = titleL; // self.descL = descL; self.promteL = promteL; self.selectBtn = selectBtn; } - (void)selectAction { if (self.ChooseBlock) { self.ChooseBlock(); } } - (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel { _examineAddModel = examineAddModel; self.titleL.text = examineAddModel.title; if (examineAddModel.dataArr.count > 0) { self.promteL.hidden = YES; CGFloat tableViewH = examineAddModel.dataArr.count * 40.f; [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(tableViewH)); }]; [self.tableView reloadData]; }else { self.promteL.hidden = NO; self.promteL.text = examineAddModel.prompt; [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(1)); }]; } if ([examineAddModel.key isEqualToString:@"Materials"]) { self.selectBtn.hidden = YES; }else { self.selectBtn.hidden = NO; } // NSMutableString *strM = [[NSMutableString alloc] init]; // if (examineAddModel.dataArr.count > 0) { // self.promteL.hidden = YES; // for (NSInteger i = 0 ; i < examineAddModel.dataArr.count; i++) { // NSDictionary *obj = examineAddModel.dataArr[i]; // NSString *str; // if ([examineAddModel.key isEqualToString:@"Materials"] || [examineAddModel.key isEqualToString:@"rel_materialjson"]) { // str = [obj valueForKey:@"bm_materialname"]; // }else { // str = [obj valueForKey:@"NAME_"]; // } // if (i == examineAddModel.dataArr.count - 1) { // [strM appendFormat:@"%@",str]; // }else { // [strM appendFormat:@"%@\n",str]; // } // } // self.descL.text = strM.copy; // }else { // self.descL.text = @""; // self.promteL.hidden = NO; // self.promteL.text = examineAddModel.prompt; // } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.examineAddModel.dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PBListDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; if ([self.examineAddModel.key isEqualToString:@"Materials"] || [self.examineAddModel.key isEqualToString:@"rel_materialjson"]) { id obj = self.examineAddModel.dataArr[indexPath.row]; if ([obj isKindOfClass:[PBArtifactsInfoModel class]]) { PBArtifactsInfoModel *model = (PBArtifactsInfoModel *)obj; cell.isNotEdit = NO; cell.title = model.bm_materialname; }else { PBArtifactsInfoModel *model = [PBArtifactsInfoModel yy_modelWithDictionary:obj]; cell.isNotEdit = YES; cell.title = model.bm_materialname; } }else { cell.isNotEdit = YES; NSDictionary *dict = self.examineAddModel.dataArr[indexPath.row]; cell.title = [dict valueForKey:@"NAME_"]; } cell.deleteBlock = ^{ if (self.DeleteBlock) { self.DeleteBlock(indexPath.row); } }; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.ToViewBlock) { self.ToViewBlock(indexPath.row); } } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end