tableViewCell 自适应高度

只需要改两个类即可


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       static NSString *identifier = @"Cell";
       CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
       if (!cell) {
           cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] lastObject];
       }
       CGSize boundSize = CGSizeMake(216, CGFLOAT_MAX);
       cell.workSituation.text = @"string......";
       cell.workSituation.numberOfLines = 0;
       CGSize requiredSize = [cell.workSituation.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:boundSize lineBreakMode:UILineBreakModeWordWrap];
       CGRect rect = cell.frame;
        rect.size.height = requiredSize.height;
        cell.frame = rect;
       return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
        return cell.frame.size.height;
}

你可能感兴趣的:(tableViewCell 自适应高度)