increase uitableviewcell height simultaneously increasing the inner UITextView

前端 未结 8 1548
花落未央
花落未央 2021-02-02 17:13

I create a UITableView with different types of UITableViewCell depending on the type of content to display. One of this is a UITableViewCell

8条回答
  •  -上瘾入骨i
    2021-02-02 17:34

    You should calculate newHeight for cell before loading cell. Instead of calculating newHeight in textViewDidChange, calculate it in heightForRowAtIndexPath and return same as

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      if ([current_field.tipo_campo isEqualToString:@"text_area"])
      {
          NSString *string = current_field.valore;
          CGSize stringSize = [string sizeWithFont:[UIFont boldSystemFontOfSize:15] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:UILineBreakModeWordWrap];
          CGFloat height = ([string isEqualToString:@""]) ? 30.0f : stringSize.height+10;
    
          return height + 10.0f;
      }
      else
      {
          return 44.0f;
      }
    }
    

提交回复
热议问题