• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 正确定义 UITableViewCell 调整大小的约束

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:01:03 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我目前正面临这个问题,我需要定义一个动态高度 UITableViewCell。

enter image description here

红线对应于可调整大小的 View (将垂直增长),蓝色标签有 3 个约束:两个用于上面的每个直接红色 View (>= 8),一个具有 170 和较低优先级的 super View 。

绿色的对superview有底部约束(5)

当我尝试运行我的代码时,它给了我这个:

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:0x19d65bb0 V:[UIView:0x19d9a9a0(5)]>",
 "<NSLayoutConstraint:0x19d667d0 V:[UILabel:0x19de4180(19)]>",
 "<NSLayoutConstraint:0x19d5ba70 V:[UILabel:0x19d61870(19)]>",
 "<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>",
 "<NSLayoutConstraint:0x19d35d30 V:[UIView:0x19d36130(0)]>",
 "<NSLayoutConstraint:0x19e7b310 V:|-(5)-[UILabel:0x19d6b520]   (Names: '|':UITableViewCellContentView:0x19d97580 )>",
 "<NSLayoutConstraint:0x17d0b060 V:[UILabel:0x19d6b520]-(5)-[UIView:0x19d9a9a0]>",
 "<NSLayoutConstraint:0x17d0a480 V:[UIView:0x19d9a9a0]-(8)-[UILabel:0x19de4180]>",
 "<NSLayoutConstraint:0x17d0c920 V:[UILabel:0x19de4180]-(8)-[UILabel:0x19d61870]>",
 "<NSLayoutConstraint:0x17d0a100 V:[UILabel:0x19d61870]-(8)-[UIView:0x19d839e0]>",
 "<NSLayoutConstraint:0x17d11ad0 V:[UIView:0x19d839e0]-(8)-[UILabel:0x19d36e80]>",
 "<NSLayoutConstraint:0x19e742a0 V:[UILabel:0x19d36e80]-(8)-[UILabel:0x19d36770]>",
 "<NSLayoutConstraint:0x19ed84a0 V:[UILabel:0x19d36770]-(8)-[UIView:0x19d36130]>",
 "<NSLayoutConstraint:0x19e76410 V:[UIView:0x19d36130]-(>=8)-[UILabel:0x19d35560]>",
 "<NSLayoutConstraint:0x19ed8af0 V:[UILabel:0x19d35560]-(8)-[UITextView:0x1832ba00]>",
 "<NSLayoutConstraint:0x19e7abf0 V:[UITextView:0x1832ba00]-(8)-[UILabel:0x19e7d890]>",
 "<NSLayoutConstraint:0x19e83d90 V:[UILabel:0x19e7d890]-(8)-[UITextView:0x18a95e00]>",
 "<NSLayoutConstraint:0x19e7b520 V:[UITextView:0x18a95e00]-(5)-|   (Names: '|':UITableViewCellContentView:0x19d97580 )>",
 "<NSAutoresizingMaskLayoutConstraint:0x19d46fc0 h=--& v=--& V:[UITableViewCellContentView:0x19d97580(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

所以,问题是: 实现这一目标的正确方法是什么???



Best Answer-推荐答案


你是否使用 storyboard,如果是,简单地转到 Editor->Resolve Auto Layout Issues->Clear All Constraints In .... Controller ,然后 Add Missing Constraints In ...... Controller

它将帮助您解决打破 View 之间约束的问题

关于ios - 正确定义 UITableViewCell 调整大小的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19614241/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap