为动态单元格高度创建简单的应用程序。
我有自定义 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)tableViewUITableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)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;
}
提前致谢。
如果你不想给出高度限制,你应该给出顶部、底部、前导、尾随。
如果你需要高度限制,那么你应该给 (leading,trailing,top,height) 或 (leading,trailing,centerY,height)
确保在 heightForRow 方法中返回正确的高度。
如果你想使用UITableViewAutomaticDimension
在您的情况下,estimatedRow 高度是 IB 中的确切行高。
关于ios - UITableViewCell中的自动布局约束不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44436336/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |