除非我将视图添加到容器视图而不是contentView,否则UITableViewCell不起作用 [英] UITableViewCell doesn't work unless I add views to a container view rather than contentView

查看:242
本文介绍了除非我将视图添加到容器视图而不是contentView,否则UITableViewCell不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是参考此帖子(TLDR;如果正确使用了自动布局",则应该自动计算UITableViewCell的高度) ).

This is in reference to this post (TLDR; UITableViewCell heights should be calculated automatically if you are using Auto Layout properly).

如果我直接将视图添加到contentView,则继续出现此错误:

If I add the views directly to contentView, I keep on getting this error:

018-11-25 02:17:33.514881+0200 [78571:855018] [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:0x2825f0be0 V:|-(76)-[.TTRLabel:0x10e7c7e40'DRIVER']   (active, names: '|':UITableViewCellContentView:0x10e7cb700 )>",
    "<NSLayoutConstraint:0x2825f0b90 V:[.TTRLabel:0x10e7c7e40'DRIVER']-(10)-[.TTRLabel:0x10e7c8420'TIME']   (active)>",
    "<NSLayoutConstraint:0x2825f1c70 V:[.TTRLabel:0x10e7c8420'TIME']-(10)-[.TTRLabel:0x10e7c8a00'ADDRESS']   (active)>",
    "<NSLayoutConstraint:0x2825f1ea0 .TTRLabel:0x10e7c96a0' new office '.bottom == UITableViewCellContentView:0x10e7cb700.bottom - 26   (active)>",
    "<NSLayoutConstraint:0x2825f1f40 .TTRLabel:0x10e7c96a0' new office '.lastBaseline == .TTRLabel:0x10e7c8a00'ADDRESS'.lastBaseline   (active)>",
    "<NSLayoutConstraint:0x2825f34d0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x10e7cb700.height == 44   (active)>"
)

我的问题在于这部分

<NSLayoutConstraint:0x2825f34d0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x10e7cb700.height == 44   (active)>"

它坚持认为tableViewCell的高度只是标准的44(因此忽略了我所有的自动布局工作!

It's insisting that the tableViewCell height is just the standard 44 (and thus is ignoring all my autolayout work!

解决问题的唯一方法就是运行

The only thing that solves the problem is running this

self.contentView.autoPinEdgesToSuperviewEdges()

这很奇怪,b/c在任何地方都没有记录,并且在宏大的计划中没有意义.

which is weird, b/c it's not documented anywhere and doesn't make sense in the grand scheme of things.

这里是完整的 UITableViewCell代码供参考.

推荐答案

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {

}

//我添加了此代码,它对我有用,我的问题是在iOS 10上

// I add this code, it works for me, my question is on iOS 10

这篇关于除非我将视图添加到容器视图而不是contentView,否则UITableViewCell不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆