Note that there are some explanatory texts on larger screens.

plurals
  1. POResize tableview NSLayoutConstraint
    primarykey
    data
    text
    <p>Hi I have a tableView which I change the width programmatically by his constraint:</p> <pre><code> self.widthTableLeft.constant = self.view.frame.size.width; </code></pre> <p>I do this in the viewDidLoad. </p> <p>In the delegate method:</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath </code></pre> <p>I need the contentview frame of each cell to calculate the hight of the cell, but when get it, this is the old size, I mean the size if I wouldn't have done the resize.</p> <p>When the table is showed the size of the table is right but the hight of the cell is wrong. </p> <p>I have tried to call:</p> <pre><code>[cell setNeedsUpdateConstraints]; [cell updateConstraintsIfNeeded]; [cell.contentView setNeedsLayout]; [cell.contentView layoutIfNeeded]; </code></pre> <p>The question is, before to show the view of my view controller, when is the best place to update the width constraint of a UITableView and to get the right contentView in the cells in the method heightForRowAtIndexPath.</p> <p>Sorry but I'm lost, could you give me any ideas?</p> <p>Thanksssss</p> <p><strong>UPDATE</strong></p> <p>This is the code in heightForRowAtIndexPath</p> <pre><code>static const NSInteger ROC_TITLE_LABEL_TAG = 2; - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { ROCAgendaItemDetailEntity *agendaItemDetail = [self.listRight objectAtIndex:indexPath.row]; UITableViewCell *cell = [self.tableLeft dequeueReusableCellWithIdentifier:@"cellVideo"]; //I get the label which will make the cell bigger UILabel *titleLabel = (UILabel *)[cell viewWithTag:ROC_TITLE_LABEL_TAG]; //We init the height title with the min height. float extraSpaceHeightLabel = 0; if (agendaItemDetail.agendaItem.title.length &gt; 0) { //I will use his width to get the hight that I need to write all text float width = titleLabel.frame.size.width; CGSize size = CGSizeMake(width, CGFLOAT_MAX); //we get the size CGSize sizeTitleLabel = [agendaItemDetail.agendaItem.title sizeWithFont:[ROCTextsInformation imagoMed:15] constrainedToSize:size lineBreakMode:titleLabel.lineBreakMode]; //we substract the current height of the label to know the extra space to write all text sizeTitleLabel.height -= titleLabel.frame.size.height; extraSpaceHeightLabel = sizeTitleLabel.height; } //The final hight will be the contenViewHeight pluss the extra space needed. return cell.contentView.frame.size.height + extraSpaceHeightLabel; } </code></pre> <p>and this is the cell in the table view</p> <p><img src="https://i.stack.imgur.com/pxQ7O.png" alt="enter image description here"></p> <p>Thanks again</p>
    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.
    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