increase uitableviewcell height simultaneously increasing the inner UITextView

前端 未结 8 1543
花落未央
花落未央 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条回答
  •  攒了一身酷
    2021-02-02 17:32

    To resize the cells you would use code similar to this

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
        NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
        CGSize size = // calculate size of new text
    CGRect frame = textView.frame;
    frame.size.height = textView.contentSize.height;
    textView.frame = frame;
    
        if ((NSInteger)size.height != (NSInteger)[self tableView:nil heightForRowAtIndexPath:nil]) {
    
            // if new size is different to old size resize cells. 
    
    
            [self.tableView beginUpdates];
            [self.tableView endUpdates];
        }
        return YES;
    }
    

提交回复
热议问题