Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling `[UIView -systemLayoutSizeFittingSize:]` on a UITableViewCell always fails
    primarykey
    data
    text
    <p>I want to use auto-layout for UITableViewCells. These table cells have a dynamic height (depending on text length).</p> <p>I'm using <a href="http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/systemLayoutSizeFittingSize:" rel="noreferrer"><code>[UIView -systemLayoutSizeFittingSize:]</code></a> to calculate the appropriate cell height (to return in <code>[UITableView -heightForRowAtIndexPath:]</code>) but I keep getting the following results:</p> <ul> <li><p>If I pass <code>UILayoutFittingCompressedSize</code>, I get back a CGSize of (0,0).</p></li> <li><p>If I pass <code>UILayoutFittingExpandedSize</code>, my app crashes with this error:</p> <blockquote> <p>*** Assertion failure in -[NSISLinearExpression incrementConstant:], /SourceCache/Foundation_Sim/Foundation-1043.1/Layout.subproj/IncrementalSimplex/NSISLinearExpression.m:620</p> </blockquote></li> </ul> <p>(My guess is that this means some number is infinite.)</p> <p>My implementation is simple. I calculate the height for each object, and then cache it:</p> <pre><code>MessageCell *cell = // allocate a new cell... // set up the cell (assign text, images, etc) CGSize size = [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; self.cellHeight = size.height; // size always equals (0, 0) </code></pre> <p>I hypothesize that this is a problem with the constraints I set, but:</p> <ul> <li>If I manually set <code>cellHeight</code> to a large value, the cells all look fine except the height is wrong.</li> <li>Interface Builder gives me no warnings about ambiguous restraints</li> <li><code>[cell hasAmbiguousLayout]</code> returns <code>NO</code>.</li> <li>My cell has, among other things, an image set at 48x48, so a size of (0, 0) shouldn't satisfy all the constraints.</li> </ul> <p>Any ideas?</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.
 

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