ios - UITableViewCell中的自动布局约束不匹配
<p><p>为动态单元格高度创建简单的应用程序。</p>
<p>我有自定义 <code>UITableViewCell</code> 并且我有一些控件。我已经修复了所有控件的约束。约束集后 Tableview 不显示任何错误。 Tableview 运行时单元格高度没问题,但是当我检查控制台日志时,它给了我如下所示的错误。</p>
<pre><code>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-08 17:54:22.184177+0530 Test 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.
(
"<NSLayoutConstraint:0x600000286680 UILabel:0x7fe86bd1c4e0'Label'.height == 50 (active)>",
"<NSLayoutConstraint:0x600000286810 V:|-(14)- (active, names: '|':UITableViewCellContentView:0x7fe86bd1c220 )>",
"<NSLayoutConstraint:0x600000286860 V:-(15)-| (active, names: '|':UITableViewCellContentView:0x7fe86bd1c220 )>",
"<NSLayoutConstraint:0x600000286cc0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fe86bd1c220.height == 49 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000286680 UILabel:0x7fe86bd1c4e0'Label'.height == 50 (active)>
</code></pre>
<p><strong>Bellow 是我的 TableView 及其约束。</strong>
<a href="/image/9kTpQ.png" rel="noreferrer noopener nofollow"><img src="/image/9kTpQ.png" alt="enter image description here"/></a> </p>
<p><strong>下面是我的 TableView 代码</strong></p>
<pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = ;
NSString * strAction = arrActionList;
if () {
cell.lblActionHeight.constant = 50;
}
else{
cell.lblActionHeight.constant = 20;
}
cell.lblAction.text = strAction;
;
return cell;
}
</code></pre>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果你不想给出高度限制,你应该给出顶部、底部、前导、尾随。</p>
<p>如果你需要高度限制,那么你应该给 (leading,trailing,top,height) 或 (leading,trailing,centerY,height)</p>
<p>确保在 heightForRow 方法中返回正确的高度。</p>
<p>如果你想使用<code>UITableViewAutomaticDimension</code></p>,你需要指定估计的行高
<p>在您的情况下,estimatedRow 高度是 IB 中的确切行高。</p></p>
<p style="font-size: 20px;">关于ios - UITableViewCell中的自动布局约束不匹配,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/44436336/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/44436336/
</a>
</p>
页:
[1]