自定义cell中view的布局出错(2)
作者:
小五92 | 来源:发表于
2018-11-21 16:55 被阅读21次
问题:在自定义cell中,为了减少一层view,把cell的contentView赋给了一个自定义viewA,然后基于self,对viewA设置了约束,发现约束有时有效果有时候没有。
解决:取消对contentView对约束布局。
分析:

contentView.png
官方文档给的解释:contentVIew是UITableVIewCell显示内容的默认父View;如果想通过添加其他views来定制单元格,那么您应该将它们添加到contentView中,以便它们在cell转换到或退出编辑模式时处于适当的位置。
1、contentView是cell的默认superView,因此不可以对它进行局部修改。
2、子view要加到contentVIew中,因为编辑模式需要操作它
cell的布局

cell默认布局.png

contentView中包含的View.png

编辑状态下cell布局.png
参考链接:
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1
本文标题:自定义cell中view的布局出错(2)
本文链接:https://www.haomeiwen.com/subject/fmmcqqtx.html
网友评论