uitableview - UIView-Encapsulated-Layout-Width/Height 约束为零

标签 uitableview autolayout

有许多关于 UITableView 的自动布局的堆栈溢出问题与 UIView-Encapsulated-Layout-Width 有关的单元格和节页眉/页脚UITableView 的约束用于使其组件的大小正确:

  • what is NSLayoutConstraint "UIView-Encapsulated-Layout-Height" and how should I go about forcing it to recalculate cleanly
  • iOS 8.3 'UIView-Encapsulated-Layout-Width' in Custom Keyboard
  • Auto-layout: What creates constraints named UIView-Encapsulated-Layout-Width & Height?
  • What is a 'UIView-Encapsulated-Layout-Width' constraint?

  • 这些约束的目的似乎很明确——它们允许 UITableView还有UICollectionView与约束布局接口(interface)并传递其关于单元格(和其他组件)应该有多大的规范。

    大多数问题似乎是人们有一组 必填 与这些封装约束不兼容的约束也需要 0 的大小.最可行的答案似乎是将用户定义的约束的优先级降低到 999以便框架可以覆盖它们。

    然而——我有兴趣了解的是为什么 UITableView需要 0 的宽度对于它的一种观点? 这是一个错误吗?还是使用不当的结果?还是完全有道理?
    0 的高度限制有时是有道理的,如果细胞从无到有扩展。降低优先级是处理此问题的好方法。但是为什么细胞会得到 宽度 0 ?

    最佳答案

    UIView 没有固有大小,因此需要宽度和高度约束。
    UIView-Encapsulated-Layout-Width UIView-Encapsulated-Layout-Height 最初由 UICollectionView/UITableView 创建。稍后根据 sizeForItem 或 heightForRowAtIndexPath 委托(delegate)方法设置约束常量。确保在 cellForItem/cellForRow 方法中创建的 UICollectionViewCell/UITableViewCell 将具有准确的大小。

    关于uitableview - UIView-Encapsulated-Layout-Width/Height 约束为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31520075/

    相关文章:

    iphone - 从 MutableArray 加载的 UITableView 变成一个复选框列表

    ios - UITableView:删除行和添加新行后,新行不可选择

    swift - 设置页脚 View UITableView 的背景颜色不起作用

    ios - 为什么动画 block 中的 alpha 和约束常量位置不同

    ios - 在 Storyboard中将 UITableView 的 rowHeight 设置为 UITableViewAutomaticDimension?

    iphone - 键入时调整 UITextField 的大小(通过使用自动布局)

    arrays - 更改数组后无法在 Tableview 中重新加载数据?

    ios - Swift TableView 滚动到顶部

    ios - dismissViewControllerAnimated :completion: causing memory crash

    ios - Xcode复选框在哪里 "Translates Autoresizing Mask Into Constraints"