UITableViewCellAccessoryCheckmark 和 AutoLayout 约束 [英] UITableViewCellAccessoryCheckmark and AutoLayout constraints

查看:25
本文介绍了UITableViewCellAccessoryCheckmark 和 AutoLayout 约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义 UITableViewCell 并管理我的单元格的选择.当单元格被选中并显示复选标记时,单元格 Content View 宽度缩小,我的带有尾随约束的标签向左移动.如何有效避免内容移动?

I have custom UITableViewCell and manage selection of my cells. When the cell is selected and the checkmark is presented, the cell Content View width shrinks and my labels with trailing constraints move to the left. How can I effectively avoid the content move?

我不想将约束设置为领先,因为我有灵活的 tableview 宽度并且它们是右对齐的.当我想通过 IBOutlets 更新代码中标签的约束时,我遇到了麻烦,因为我在 cellForRow: 中返回了 UITableViewCell 的多个子类,我得到了尝试在代码中设置约束时,didSelectRowAtIndexPath: 中出现无法识别的选择器错误.任何优雅的解决方案?谢谢.

I did not want to set the constraints to leading as I have flexible tableview width and they are right aligned. When I want to update label's constraints in code via its IBOutlets I went into trouble as I return multiple subclasses of UITableViewCell in cellForRow: and I got unrecognized selector error in didSelectRowAtIndexPath: when trying to set constraints in code. Any elegant solution? Thanks.

推荐答案

这种行为是设计使然.

获得所需行为的最简单方法是在每个单元格上设置一个空的附件视图,这会将所有内容向左移动与复选标记相同的距离.

The simplest way to get the behavior you want is to set an empty accessory view on every cell which will move all the content to the left the same distance as the checkmark.

这篇关于UITableViewCellAccessoryCheckmark 和 AutoLayout 约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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