ios – 自动调整大小UITableViewCell:无法同时满足约束

ios – 自动调整大小UITableViewCell:无法同时满足约束,第1张

概述我正在尝试实现一个UITableViewCell,它自动调整其高度以适应可用内容.我现在有以下布局,但每当我运行程序时,调试器会抛出各种“无法同时满足约束”错误.我设置约束的方式有问题吗? [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constr 我正在尝试实现一个UItableVIEwCell,它自动调整其高度以适应可用内容.我现在有以下布局,但每当我运行程序时,调试器会抛出各种“无法同时满足约束”错误.我设置约束的方式有问题吗?

[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:0x60800009c2f0 UIImageVIEw:0x7fd389002f50.height == 60   (active)>","<NSLayoutConstraint:0x60800009a8b0 UIImageVIEw:0x7fd389002f50.top == UItableVIEwCellContentVIEw:0x7fd389009b20.topmargin + 4   (active)>","<NSLayoutConstraint:0x608000097ca0 UItableVIEwCellContentVIEw:0x7fd389009b20.bottommargin >= UIImageVIEw:0x7fd389002f50.bottom + 4   (active)>","<NSLayoutConstraint:0x600000097d40 'UIVIEw-Encapsulated-Layout-Height' UItableVIEwCellContentVIEw:0x7fd389009b20.height == 80   (active)>")Will attempt to recover by breaking constraint <NSLayoutConstraint:0x60800009c2f0 UIImageVIEw:0x7fd389002f50.height == 60   (active)>

为了完整起见,这是我用于测试的简单代码.

“ListVIEwController.m”

- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    // Do any additional setup after loading the vIEw,typically from a nib.    tableVIEw.rowHeight = UItableVIEwautomaticDimension;    tableVIEw.estimatedRowHeight = 40;}- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw {    return 1;}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    return 40;}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    ListtableVIEwCell *cell = (ListtableVIEwCell *)[tableVIEw dequeueReusableCellWithIDentifIEr:@"ListCell" forIndexPath:indexPath];    [self configureCell:cell atIndexPath:indexPath];    return cell;}- (BOol)tableVIEw:(UItableVIEw *)tableVIEw canEditRowAtIndexPath:(NSIndexPath *)indexPath {    // Return NO if you do not want the specifIEd item to be editable.    return NO;}- (voID)configureCell:(ListtableVIEwCell *)cell atIndexPath:(NSIndexPath *)indexPath {    cell.selectionStyle = UItableVIEwCellSelectionStyleNone;    cell.hasProfile = (arc4random_uniform(10) < 3);    cell.hasSecondFIEld = (arc4random_uniform(10) < 3);}

ListVIEwCell.h

@interface ListtableVIEwCell : UItableVIEwCell {    IBOutlet NSLayoutConstraint *pictureWIDthConstraint;    IBOutlet NSLayoutConstraint *pictureHeightConstraint;    IBOutlet NSLayoutConstraint *pictureBottomTrailingConstraint;    IBOutlet NSLayoutConstraint *subheaderHeightConstant;    IBOutlet UILabel *subheaderLabel;}@property (nonatomic,assign) BOol hasProfile;@property (nonatomic,assign) BOol hasSecondFIEld;@end

ListVIEwCell.m

- (voID)setHasProfile:(BOol)hasProfile {    _hasProfile = hasProfile;    if (!hasProfile) {        pictureHeightConstraint.constant = 0;        pictureWIDthConstraint.constant = 0;    }    else {        pictureHeightConstraint.constant = 60;        pictureWIDthConstraint.constant = 60;    }}- (voID)setHasSecondFIEld:(BOol)hasSecondFIEld {    _hasSecondFIEld = hasSecondFIEld;    if (!hasSecondFIEld) {        subheaderLabel.text = @"";        subheaderHeightConstant.constant = 0;    }    else {        subheaderLabel.text = @"Second Label";        subheaderHeightConstant.constant = 21;    }}
解决方法 该错误表示存在一些与您的imagevIEw的高度60冲突的其他约束,并且此约束被修改以便可以满足所有约束.

您可以调整以查看哪个约束与该高度冲突,或者您可以自己解决它.为此,请单击图像高度上的编辑按钮,然后将优先级更改为999

总结

以上是内存溢出为你收集整理的ios – 自动调整大小UITableViewCell:无法同时满足约束全部内容,希望文章能够帮你解决ios – 自动调整大小UITableViewCell:无法同时满足约束所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1018165.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存