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

ios - 更改 UITableViewCell 大小给我一个错误

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

我在 static UITableViewCell 中有一个 UIView。我在 view 中添加了高度 constraint。我认为,动画 views 高度变化的正确方法是这样的:

self.myViewsHeightConstraint.constant = 100; // Coming from 0 and vice versa
[UIView animateWithDuration:0.3f animations:^{
    [self.view layoutIfNeeded];        
}];

我将 tableView 行高设置为:

tableView.estimatedRowHeight = 40;
self.tableView.rowHeight = UITableViewAutomaticDimension; 

现在我需要更新 cells 高度。所以我认为 begin/endUpdate 是合适的。当 veiwcell 对其高度进行动画处理时,它们不会同步,因此由于它们的动画时间不完全相同,我收到以下警告:

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:0x7f8d62d15670 V:[tagResultTableView:0x7f8d62d901a0(107)]>",
    "<NSLayoutConstraint:0x7f8d62cea010 tagResultTableView:0x7f8d62d901a0.top == UITableViewCellContentView:0x7f8d62d8fd50.topMargin - 8>",
    "<NSLayoutConstraint:0x7f8d62cf0760 V:[tagResultTableView:0x7f8d62d901a0]-(8)-[UILabel:0x7f8d62d2e2e0'Limit: Up to 5 tags']>",
    "<NSLayoutConstraint:0x7f8d62cf0800 UILabel:0x7f8d62d2e2e0'Limit: Up to 5 tags'.bottom == UITableViewCellContentView:0x7f8d62d8fd50.bottomMargin>",
    "<NSLayoutConstraint:0x7f8d62f726d0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f8d62d8fd50(32)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8d62d15670 V:[tagResultTableView:0x7f8d62d901a0(107)]>

如果我的逻辑是正确的,我怎么能在同一时间为它们设置动画。或者我怎样才能为它们设置动画,以免出现错误?



Best Answer-推荐答案


如果您想确保 Cell 保持静态且不更改,请执行此方法:

- (CGFloat)tableViewUITableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath{}

并且里面有一个return语句,返回单元格高度的最终值。

关于ios - 更改 UITableViewCell 大小给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31152124/

回复

使用道具 举报

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

本版积分规则

关注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