Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamic height of UITableViewCell depending upon the Text
    primarykey
    data
    text
    <p>I have a grouped tableview with a right detail cell layout. Now I got my data back from my server. Sometimes it happens that I got back a very large text. So the tableviewCell should be higher than the others. You can see the screenshot of my problem over here.</p> <p><img src="https://i.stack.imgur.com/KFILZ.png" alt="enter image description here"></p> <p>Like you can see in my first cell I have a very large text. Now I want that the height of the cell grows with the length of the text, so i can always see the entire text instead off the '...' This is what I have in code at te moment.</p> <pre><code>#define PADDING 10.0f - (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath { Subscription *sub = [_dictTask valueForKeyPath:@"subscription"]; NSArray *meta = sub.meta.allObjects; NSString *text = [[meta objectAtIndex:indexPath.row]valueForKey:@"sum_value"]; CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(self.tableView.frame.size.width - PADDING * 3, 1000.0f)]; return textSize.height + PADDING * 3; } </code></pre> <p><strong>EDIT</strong> Code I have at the moment.</p> <pre><code>- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath { Subscription *sub = [_dictTask valueForKeyPath:@"subscription"]; NSArray *meta = sub.meta.allObjects; NSString *text = [[meta objectAtIndex:indexPath.row]valueForKey:@"sum_value"]; UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0]; CGSize constraintSize = CGSizeMake(330.0f, 400); // Make changes in width as per your label requirement. CGSize textSize = [text sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; return textSize.height; } </code></pre> <p>And this is the result.</p> <p><img src="https://i.stack.imgur.com/fzN8c.png" alt="enter image description here"></p> <p><strong>EDIT CellForRowAtIndexPath</strong></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { Subscription *sub = [_dictTask valueForKeyPath:@"subscription"]; NSArray *meta = sub.meta.allObjects; static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.textLabel.text = [[meta objectAtIndex:indexPath.row]valueForKey:@"sum_label"]; cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.text = [[meta objectAtIndex:indexPath.row]valueForKey:@"sum_value"]; cell.textLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]; cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18]; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload