ios - 使 CollectionView 和 TableView 高度动态化

标签 ios swift uitableview uicollectionview

在显示的 xib 中,我有一个 Collection View 和一个 TableView 。我希望让它们的高度动态化,因为有时两种 View 都没有任何显示,否则高度可以是任何东西。

我能够通过不添加高度来使 Collection View 动态化,但我不得不添加 TableView ,从那时起两个组件都存在缺少约束错误 - 需要约束:Y 位置或高度

(xib中的所有其他组件都有固定的高度)

enter image description here

最佳答案

为此你需要为表格和集合的高度创建两个导出,然后根据行数做

 self.tableHeight.constant = 100 * numberOfTblRows
 self.collHeight.constant = 100 * numberOfCollRows
 self.view.layoutIfNeeded()

关于ios - 使 CollectionView 和 TableView 高度动态化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56742937/

相关文章:

ios - MessageComposeViewController 不调用委托(delegate)

ios - MPMoviePlayerController 切换视频

ios - 无法将具有通用类型的类添加到 swift Realm

ios - CollectionViewCells 中重复的 TableView

swift - 如何从界面生成器中检索 key

uitableview - Xcode 6.1.1、iOS 8.1 SDK 上的 Storyboard 中静态或原型(prototype) UITableViewCell subview 的大小调整不正确

swift - 将 TableView 中的部分添加到我现有的列表?

javascript - 限制 App Store 上的移动应用程序

ios - 如何避免 Reusable Cell 的复制行为

ios - 如何使用 Swift - 在 textView 中自动完成