Home  >  Q&A  >  body text

ios - UITableHeaderView 使用 Autolayout 如何使内容自适应

我想让内容自动填充 UITableHeaderView, 使得其高度能够随着内容的变化而变化。但是,如果我直接设置 UITableHeaderView 为 translatesAutoresizingMaskIntoConstraints = NO 会报错 "Assertion failure in -[UITableView layoutSublayersOfLayer:]"。 如果不设置改属性,约束布局会出错 “Unable to simultaneously satisfy constraints.” 该如何解决,或者有没有更好的实现目标的解决方案?谢谢。

阿神阿神2711 days ago458

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-17 16:51:22

    After changing the content, call setNeedLayout and layoutIfNeed, and get the frameview.frame = frame给tableView.tableHeaderView重新赋值这样tableView.tableHeaderView = view.

    reply
    0
  • Cancelreply