Resize iOS 8 UITableViewCell displaying "Unable to satisfy constraints at the same time"

I created a UITableViewCell in a storyboard and used an automatic layout to place everything in the hope that iOS 8 would automatically determine the cell height for me. My cell has two labels, one of which is a multi-line label with a preferred automatic width.

For reference, the cell height is 208, but the height is set to "Default." The table row height is set to 208.

In the field of view loaded, I run the following code:

self.tableView.estimatedRowHeight = 100;
self.tableView.rowHeight = UITableViewAutomaticDimension;

This works great when displaying cells for the first time, everything looks right. The problem is that the cell is reused, it will distort things incorrectly. Based on this post , I noticed that I might need to run the following code in cellForIndexPath:

[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];

However, when I add this code, I get a message:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one  
    you don't want. Try this: (1) look at each constraint and try to figure  
    out which you don't expect; (2) find the code that added the unwanted  
    constraint or constraints and fix it. (Note: If you're seeing  
    NSAutoresizingMaskLayoutConstraints that you don't understand, refer  
    to the documentation for the UIView property  
    translatesAutoresizingMaskIntoConstraints) 
(
    [...]
    "<NSLayoutConstraint:0x7fd108dd1ce0 UITableViewCellContentView:0x7fd108d03d00.height ==>"
)

In this particular case, I noticed that mine <tableViewCell>did not have a tag <rect>, and that is why it displayed height==. (More on the tag <rect>below ...)

Questions

  • , setNeedsUpdateConstraints updateConstraintsIfNeeded cellForRow? , ? - . UITableViewCells, , , .

<rect>

, -, <rect> <tableViewCell>. , , , ​​ , .

, ...

1. UITableViewController :

<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="VVy-eG-5ZD">
    <autoresizingMask key="autoresizingMask"/>
    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="VVy-eG-5ZD" id="o4d-7b-psa">
        <autoresizingMask key="autoresizingMask"/>
    </tableViewCellContentView>
</tableViewCell>

" " .

, <rect>.

2. UITableViewCell :

<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="SxR-MB-xdu">
    <rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
    <autoresizingMask key="autoresizingMask"/>
    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="SxR-MB-xdu" id="JDB-Ys-OoE">
        <autoresizingMask key="autoresizingMask"/>
    </tableViewCellContentView>
</tableViewCell>

" " .

, <rect>, 44 . 44 - .

3. View to 100.

, xml .

, xml xml xml:

<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="qea-mf-mRA">
    <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>

... :

<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="100" sectionHeaderHeight="22" sectionFooterHeight="22" id="qea-mf-mRA">
    <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>

, , rowHeight="100" from rowHeight="44".

4.

, 100, - 44 <rect>:

<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="wcV-YB-1eG">
    <rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
    <autoresizingMask key="autoresizingMask"/>
    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="wcV-YB-1eG" id="xM8-zX-Nrh">
        <autoresizingMask key="autoresizingMask"/>
    </tableViewCellContentView>
</tableViewCell>

5. , ( 55)

rowHeight="55" <tableViewCell>, <rect> :

<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="55" id="wcV-YB-1eG">
    <rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
    <autoresizingMask key="autoresizingMask"/>
    <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="wcV-YB-1eG" id="xM8-zX-Nrh">
        <autoresizingMask key="autoresizingMask"/>
    </tableViewCellContentView>
</tableViewCell>

" " " ", "55" " ".

6. -

<rect>:

<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="2pz-XF-uhl" style="IBUITableViewCellStyleDefault" id="m0d-ak-lc9">
    <rect key="frame" x="0.0" y="86" width="320" height="44"/>
    <autoresizingMask key="autoresizingMask"/>

, , , , , , 600, - 320 . , , iPhone Universal.

<rect>?

  • UITableViewController: NO
  • Master-Detail: YES
  • UITableViewCell : YES

  • ?
  • , ​​?
  • // Interface Builder, XML?

, :

A. <rect>

:

Unable to simultaneously satisfy constraints ...
"<NSLayoutConstraint:0x7fb51430b220 UITableViewCellContentView:0x7fb514309340.height ==>"

. <rect>

- 1 65, .

:

<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>

:

Unable to simultaneously satisfy constraints ...
"<NSLayoutConstraint:0x7fe3104ce760 UITableViewCellContentView:0x7fe3104e00d0.height == 44>"

. <rect>

- 65, .

:

<rect key="frame" x="0.0" y="0.0" width="600" height="999"/>

.

  • , ?

, .

+4
1

:

[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
[cell layoutIfNeeded];
0

All Articles