动态调整 UITableView 的大小,显示为不可滚动的内容列表 [英] Adjust the size of UITableView dynamically which would display as a non-scrollable list of content

查看:28
本文介绍了动态调整 UITableView 的大小,显示为不可滚动的内容列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Swift 3.0 中开发一个项目,它在已经设置约束的 UIScrollView 中有一个 UITableView.

I'm working on a project in Swift 3.0 and it has a UITableView inside a UIScrollView that has already been set its constraints.

要求是在这个UITableView中显示一个将从数组返回的歌曲列表,但是这个UITableView的大小应该根据数组的大小动态排列,所以我不需要滚动UITableView,因为我可以看到 UITableView 中的所有歌曲(这个 UITableView 在我的 scrollView 里面,所以我可以使用我的 scrollView 在列表中上下移动).

The requirement is to display a list of songs that would return from an array in this UITableView, but the size of this UITableView should dynamically arrange according to the size of the array, so I do not need to scroll the UITableView since I can see all the songs in the UITableView (this UITableView is inside my scrollView, so instead I can use my scrollView do move up or down the list).

我将如何实现这一目标?

How would I achieve this?

推荐答案

您可以根据内容更改 tableview 的高度.

You can change height of the tableview based on the content.

var frame = tableView.frame
frame.size.height = tableView.contentSize.height
tableView.frame = frame

如果您使用自动布局为 tableview 高度创建出口并将 tableview 内容大小分配给它的常量.

If you are using autolayout create outlet for tableview height and assign tableview content size to its constant.

tableviewHeightConstraint.constant = tableview.contentSize.height

这篇关于动态调整 UITableView 的大小,显示为不可滚动的内容列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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