【发布时间】:2019-12-07 07:00:36
【问题描述】:
我正在使用 Swift 制作应用程序,但遇到了一个问题: 我有一个系统,人们可以在其中发布“帖子”,并对这些“帖子”发表评论。
为了显示这一点,我有一个 UITableViewController 子类,它以帖子作为标题,而 cmets 在单元格中。
现在我有一个需要列出这些帖子的屏幕。理想情况下,我希望将每个帖子与它的 cmets 放在一个单元格中。
这需要将 UITableViewController 子类(我们称之为PostTableViewController)嵌入到另一个 UITableViewController 的单元格中。
问题是,我不希望这些 ProfileTableViewController 中的每一个都在它们的单元格内滚动。我需要在 tableViewController 上关闭滚动,并使其高度扩展以适合其整个内容。
我已经查看了this post 上的答案,但我仍然遇到问题。目前尚不清楚 tableView 是否正确调整大小,因为 ProfileTableViewController 在其各自单元格中的高度始终为 0。如果我手动设置恒定高度约束,我可以看到其中的一部分,但我希望它自动调整大小适合 tableView。
我当前的约束设置是:
//dateView is another view in my tableViewCell
profileViewController.view.topAnchor.constraint(equalTo: dateView.bottomAnchor).isActive = true
profileViewController.view.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
profileViewController.view.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
profileViewController.view.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true
profileViewController.view.bottomAnchor.constraint(equalTo: profileViewController.tableView.tableFooterView!.bottomAnchor).isActive = true
profileViewController.tableView.topAnchor.constraint(equalTo: profileViewController.view.topAnchor).isActive = true
self.bottomAnchor.constraint(equalTo: homeViewController.view.bottomAnchor).isActive = true
那么我怎样才能让tableView自动适应它的内容,并设置约束让tableViewCell自动调整为tableView呢?
注意(1):我的界面完全是代码;没有与这种情况相关的情节提要
注意(2): ProfileTableViewControllers 的内容是动态的,因此约束需要在变化时更新。
【问题讨论】:
标签: ios swift uitableview