【发布时间】:2017-06-08 12:52:36
【问题描述】:
为动态单元格高度创建简单的应用程序。
我有自定义 UITableViewCell 并且我有一些控件。我已经修复了所有控件的约束。约束集后 Tableview 不显示任何错误。 Tableview 运行时单元格高度没问题,但是当我检查控制台日志时,它给了我如下所示的错误。
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[46461:306448] [LayoutConstraints] 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)-[UILabel:0x7fe86bd1c4e0'Label'] (active, names: '|':UITableViewCellContentView:0x7fe86bd1c220 )>",
"<NSLayoutConstraint:0x600000286860 V:[UILabel:0x7fe86bd1c4e0'Label']-(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)>
下面是我的 TableView 代码
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
NSString * strAction = arrActionList[indexPath.row];
if ([strAction isEqualToString:@"More"]) {
cell.lblActionHeight.constant = 50;
}
else{
cell.lblActionHeight.constant = 20;
}
cell.lblAction.text = strAction;
[cell.contentView layoutIfNeeded];
return cell;
}
提前致谢。
【问题讨论】:
-
为什么在tableview cellforRowatindexpath中使用约束只使用自动布局
-
每当我们尝试在表视图中以编程方式更改约束时,日志都会打印出此类警告。但是你达到了预期的结果吗?
-
如果操作名称为“更多”,则标签高度为 50。
-
@PraveenKumar tableview 单元格按我的预期显示,但仅在控制台中打印日志。
-
@Lalji 检查我的回答,它非常支持你。
标签: ios objective-c uitableview autolayout tableviewcell