Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How long are the strings you're calculating the size against? I ask because you're <code>sizeWithFont:constrainedToSize:</code> function is constraining to the full width of the cell, but your labels are probably not the full width of the cell. </p> <p>What I suspect is happening is <code>song.info</code> is just short enough that it would fit on one line if the line were the full width of the cell, and that your song <code>detail</code> is long enough that it is calculating the correct number of lines, but not so long as to exceed the calculated height.</p> <p>All of that to say, I think what you need to do is find out the widths of <code>textLabel</code> and <code>detailTextLabel</code> and set your constraints to those values.</p> <p><strong>Update - A way of calculating label widths</strong></p> <p>Since the width of the labels inside of a cell are dependent on the width of the cell, and since cell's aren't created at the time <code>heightForRowAtIndexPath:</code> is called, we need to come up with a way to know the labels' widths before they the widths are set. The only way to do this is to set the widths ourselves. Here's how I would do it:</p> <p>MyCell.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface MyCell : UITableViewCell + (CGFloat)textLabelWidthForCellOfWidth:(CGFloat)cellWidth; @end </code></pre> <p>MyCell.m</p> <pre><code>#import "MyCell.h" @implementation MyCell - (void)layoutSubviews { [super layoutSubviews]; CGRect frame = self.textLabel.frame; frame.size.width = [MyCell textLabelWidthForCellOfWidth:self.frame.size.width]; self.textLabel.frame = frame; } + (CGFloat)textLabelWidthForCellOfWidth:(CGFloat)cellWidth { // This calculation can be as complex as necessary to account for all elements that affect the label return cellWidth - 20; } @end </code></pre> <p>Then in your <code>heightForRowAtIndexPath:</code> implementation you can call the same class method:</p> <pre><code>CGFloat labelWidth = [MyCell textLabelWidthForCellOfWidth:self.tableView.frame.size.width]; // Since non-grouped cells are the full width of the tableView CGSize size2 = [detail sizeWithFont:[UIFont fontWithName:setlistFont size:detailFontSize] constrainedToSize:CGSizeMake(labelWidth, CGFLOAT_MAX)]; </code></pre> <p>You would create a separate Class Method (+) for each label that you need to reference.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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