// // Job_Detail_base.m // LNManager // // Created by EchoShacolee on 2017/4/9. // Copyright © 2017年 lee. All rights reserved. // #import "Job_Detail_base.h" #import #import @interface Job_Detail_base () @end @implementation Job_Detail_base - (void)viewDidLoad { [super viewDidLoad]; _tableViews = [[NSMutableArray alloc]init]; _heightsArr = [[NSMutableArray alloc]init]; _statusArr = [[NSMutableArray alloc]init]; _keysArr = [[NSMutableArray alloc]init]; [self setData]; } -(void)setData{ for (int i=0; i<_keysArr.count; i++) { [_statusArr addObject:@0]; [_heightsArr addObject:@normalCellH]; } } #pragma mark SegmentControll -(void)setCurrentIndex:(NSInteger)currentIndex{ if (_currentIndex != currentIndex) { //_currentIndex = currentIndex; _seg.selectedSegmentIndex = currentIndex; [self changeTableview:_seg]; } } -(void)setSegmentControllWithTitles:(NSArray *)dataArr isBttomBar:(BOOL)isBttombar{ // CGRect frame; if (dataArr.count == 1) { frame = CGRectMake(0, 0, kSize.width, 0); }else{ frame = CGRectMake(10, 0, kSize.width - 20, JOb_DETAIL_SEGBAR_HEIGHT); } _seg = [[UISegmentedControl alloc]initWithItems:dataArr]; _seg.frame = frame; _seg.selectedSegmentIndex = 0; self.currentIndex = 0; _seg.tintColor = defGreen; // _seg.apportionsSegmentWidthsByContent = YES; [_seg addTarget:self action:@selector(changeTableview:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_seg]; //1+n // CGFloat bottomBarH = 0; //判断是否需要底部处理button if (isBttombar) { bottomBarH = JOb_DETAIL_BOTTOMBAR_HEIGHT+SafeAreaBottomHeight; } _mainScroolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-CGRectGetMaxY(_seg.frame)-bottomBarH-kNavOffSet)];//导航栏不透明 _mainScroolView.pagingEnabled = YES; _mainScroolView.bounces = NO; _mainScroolView.showsVerticalScrollIndicator = NO; _mainScroolView.showsHorizontalScrollIndicator = NO; _mainScroolView.delegate = self; [self.view addSubview:_mainScroolView]; for (int i=0; i=0) { scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); } else if (scrollView.contentOffset.y>=sectionHeaderHeight) { scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0); } } #pragma mark tableviewDe - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _keysArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_statusArr[indexPath.row] isEqualToNumber:@1]) { //缓存高度 NSNumber *cellHeight = [_heightsArr objectAtIndex:indexPath.row]; if ([cellHeight isEqualToNumber:@normalCellH]) { CGFloat fontSize = 17; NSString *detail = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]]; CGFloat wid = kSize.width - [_keysArr[indexPath.row][0] widthForFont:fontSize] - 46;//46是cell边距20+20+间距6 plus CGFloat h1 = [self getHeightWithWidth:wid Font:fontSize String:detail]+1+16;//+1 cell与content 16是上下间距 CGFloat H = h1>normalCellH?h1:normalCellH; [_heightsArr replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithFloat:H]]; return H; }else{ return [cellHeight floatValue]; } } return normalCellH; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //这里返回的cell是第一个tableview的。下面对于key的判定isequal和contains的区别在于 一个是独有,一个是共有 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"]; } NSString * key = _keysArr[indexPath.row][1]; cell.textLabel.text = _keysArr[indexPath.row][0]; if ([key containsString:@"_SEX"]) { NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"男" : @"女" ; }else if ([key containsString:@"_EMPLOYSTATUS"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [status isEqualToString:@"0"] ? @"在职" : @"离职" ; }else if ([key containsString:@"_RECORD_STATUS"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ; }else if ([key containsString:@"_LOCK_STATUS"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已锁定" : @"解除锁定" ; }else if ([key containsString:@"_OCCUPATIONLEVEL"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; switch ([status integerValue]) { case 1: cell.detailTextLabel.text = @"一级"; break; case 2: cell.detailTextLabel.text = @"二级"; break; case 3: cell.detailTextLabel.text = @"三级"; break; case 4: cell.detailTextLabel.text = @"四级"; break; default: break; } }else if ([key isEqualToString:@"TCO_PLATECOLOR"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; //车牌颜色(1:蓝色; 2:黄色; 3:黑色; 4:白色; 5:绿色; 9:其他;) switch ([status integerValue]) { case 1: cell.detailTextLabel.text = @"蓝色"; break; case 2: cell.detailTextLabel.text = @"黄色"; break; case 3: cell.detailTextLabel.text = @"黑色"; break; case 4: cell.detailTextLabel.text = @"白色"; break; case 5: cell.detailTextLabel.text = @"绿色"; break; case 9: cell.detailTextLabel.text = @"其它"; break; default: break; } }else if ([key isEqualToString:@"AUDITSTUATS"]){ NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]]; cell.detailTextLabel.text = @"审核中"; switch ([status integerValue]) { case 1: cell.detailTextLabel.text = @"审核通过"; break; case 2: cell.detailTextLabel.text = @"审核拒绝"; break; default: break; } cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"审核通过" : @"未备案" ; }else{ cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]]; } if ([_statusArr[indexPath.row] isEqualToNumber:@1]) { cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.textAlignment = NSTextAlignmentLeft; }else{ cell.detailTextLabel.numberOfLines = 1; cell.detailTextLabel.textAlignment = NSTextAlignmentRight; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_tableViews indexOfObject:tableView] == 0) { if ([_statusArr[indexPath.row] isEqualToNumber:@1]) { [_statusArr replaceObjectAtIndex:indexPath.row withObject:@0]; }else{ [_statusArr replaceObjectAtIndex:indexPath.row withObject:@1]; } [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if ([tableView isEqual:_tableViews[0]] && self.headImgStr) { return 120; } return 0; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 120)]; UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100*5/6, 100)];//标准一寸照295/413 imageV.contentMode = UIViewContentModeScaleAspectFit; imageV.center = view.center; NSString *imgPath = @""; #pragma clang diagnostic push #pragma clang diagnostic ignored"-Wcompare-distinct-pointer-types" //写在这个中间的代码,都不会被编译器提示-Wcompare-distinct-pointer-types类型的警告 if (self.headImgStr != [NSNull null]) { imgPath = self.headImgStr; } #pragma clang diagnostic po [imageV sd_setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"default_headImg"]]; imageV.layer.masksToBounds = YES; imageV.layer.cornerRadius = 5; [view addSubview:imageV]; // imageV.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectHeadImg)]; [imageV addGestureRecognizer:tap]; return view; } -(void)selectHeadImg{ TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil]; imagePickerVC.allowCrop = YES; CGFloat width = kSize.width*2/3; imagePickerVC.cropRect = CGRectMake(kSize.width/6, kSize.height/2-width*3/5, width, width*6/5); // 通过block(或者代理),来得到用户选择的照片. [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets,BOOL isSelectOriginalPhoto) { [self uploadHeadImg:photos[0]]; }]; [self presentViewController:imagePickerVC animated:YES completion:nil]; } -(void)uploadHeadImg:(UIImage*)image{ //交给具体的子类去实现 } #pragma mark - 返回合适lable的高度 -(CGFloat)getHeightWithWidth:(CGFloat)wid Font:(CGFloat)fontSize String:(NSString *)str { if (str.length == 0) { return 0; } UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)]; lab.text = str; lab.numberOfLines = 0; lab.font = [UIFont systemFontOfSize:fontSize]; return [lab sizeThatFits:CGSizeMake(wid, MAXFLOAT)].height; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end