1

I have a UITextView in all the cells of a UITableview. The text view's height is increasing dynamically. As the text view size increases, I would like to increase that cell's height. I am writing as

    -(BOOL)textView:(UITextView *)textView1 shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {

        NSLog(@"textTag%d",textView1.tag);

        NSString *stringToSave = [textView1.text stringByReplacingCharactersInRange:range withString:text];
        NSLog(@"Save me: %@", stringToSave);

     CGFrame*frame =textView1.frame;
        frame.size.height = textView1.contentSize.height;
        textView1.frame = frame;

//HERE I NEED TO INCREASE THE HIGHT FOR THE PARTICULAR CELL.

if([text isEqualToString:@"\n"])
    {
        [textView1 resignFirstResponder];
    }
    return  YES;
}
user1969021
  • 39
  • 2
  • 7

3 Answers3

1

insert these lines:

//class variable, type float
newHeight = textView1.contentSize.height;
//class variable, type int
cellIndex = /*set index of your cell for which you want extended height*/
[yourTable reloadData];

below these lines:

CGFrame*frame =textView1.frame;
        frame.size.height = textView1.contentSize.height;
        textView1.frame = frame;

And in heightForRowAtIndexPath method

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == cellIndex)
    {
        return newHeight;
    }
    return regularHeigh;
}
Salman Zaidi
  • 8,426
  • 12
  • 42
  • 60
0

Add a custom growing TextView called HPGrowingTextView to your cell . Then change the height of the cell as shown in the question

Change the UITableViewCell Height According to Amount of Text

Community
  • 1
  • 1
Subbu
  • 2,013
  • 4
  • 24
  • 39
0

I think you could map the heights of the cells in a NSMutableArray. The array will contain the standard heights that you have.

You can tag the UITextView with the indexPath.row so you know which item to load from the array.

And you can override the value from the array according with the textview's height.

Then in your

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
 return [[mycellsizearray objectAtIndex:indexPath.row]floatValue];
}

Now you should have the heights according with your needs.

Bhanu
  • 1,211
  • 9
  • 17
soryngod
  • 1,807
  • 1
  • 14
  • 13