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;
}

posted on 2015-09-26 22:04  MrYude  阅读(188)  评论(0编辑  收藏  举报

导航