// // MyMessageVC.m // LNManager // // Created by EchoShacolee on 2017/9/15. // Copyright © 2017年 lee. All rights reserved. // #import "MyMessageVC.h" #define normalCellH 44 @interface MyMessageVC () { NSArray *_keysArr; NSMutableArray *_statusArr; NSMutableArray *_heightsArr; } @end @implementation MyMessageVC - (void)viewDidLoad { [super viewDidLoad]; self.holderV.hidden = YES; _keysArr = @[@[@"登录账号",@"loginCode"], @[@"所在地市",@"dqmc,qxmc"], @[@"用户级别",@"userType"],//1省级,2市级,3.区级 @[@"用户电话",@"tel"], @[@"创建用户",@"crUserName"], @[@"创建时间",@"crDate"]]; _statusArr = [[NSMutableArray alloc]init]; _heightsArr = [[NSMutableArray alloc]init]; for (int i=0; i<_keysArr.count; i++) { [_statusArr addObject:@0]; [_heightsArr addObject:@normalCellH]; } } #pragma mark - tbv代理 -(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:@"%@",MYAPPDELEGATE.userDic[_keysArr[indexPath.row][1]]]; CGFloat wid = kSize.width - [_keysArr[indexPath.row][0] widthForFont:fontSize] - 46;//46是cell边距20+20+间距6 plus CGFloat h1 = [detail heightForWid:wid Font:fontSize]+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{ UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"]; } if ([_statusArr[indexPath.row] isEqualToNumber:@1]) { cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.textAlignment = NSTextAlignmentLeft; }else{ cell.detailTextLabel.numberOfLines = 1; cell.detailTextLabel.textAlignment = NSTextAlignmentRight; } NSString * key = _keysArr[indexPath.row][1]; cell.textLabel.text = _keysArr[indexPath.row][0]; cell.detailTextLabel.numberOfLines = 0; if ([key isEqualToString:@"dqmc,qxmc"]){ cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@",MYAPPDELEGATE.userDic[@"dqmc"],MYAPPDELEGATE.userDic[@"qxmc"]]; }else if ([key isEqualToString:@"userType"]){ NSString *status = [NSString stringWithFormat:@"%@",MYAPPDELEGATE.userDic[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; } }else{ cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",MYAPPDELEGATE.userDic[key]]; } cell.textLabel.text = _keysArr[indexPath.row][0]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_statusArr[indexPath.row] isEqualToNumber:@1]) { [_statusArr replaceObjectAtIndex:indexPath.row withObject:@0]; }else{ [_statusArr replaceObjectAtIndex:indexPath.row withObject:@1]; } [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } - (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