我正在设计一个具有滚动视图的页面,并在它之上设计一个表视图(禁用滚动)。为此,我在这个问题中提到了答案-- Make UITableView not scrollable and adjust height to accommodate all cells,但没有成功。
视图的层次结构以及提供的约束-
-Main View
-Scroll视图
固定在主视图的所有侧面(0,0,0,0),约束为边距
-Content View
固定在滚动视图(0,0,0,0)上,等宽到主视图,等高到主视图(优先级- 250)
内容视图中的-Table视图
禁用滚动,从四面八方有50个点空间,高度(>=),底部间距50 (关系>=).I设置大于等于,以便动态增加高度。
现在,当我填充我的表视图时,我将代码作为
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableview.dequeueReusableCellWithIdentifier("cellreuse", forIndexPath: indexPath)
cell.textLabel?.text = name[indexPath.row]
tableview.frame.size = tableview.contentSize
return cell
}因此,当我运行我的代码时,它会增加tableview框架,但不会扩展内容大小,只是变得奇怪,因为我的滚动视图没有滚动到表视图的末尾,我的表视图也不遵守自动布局约束。
发布于 2015-12-24 05:17:27
只是我需要这么做-
tableView.frame.size = tableView.contentSize
tableHeightConstraint.constant = tableview.contentSize.height发布于 2022-07-19 07:12:25
这样,您就可以轻松地实现表的动态高度。工作在iOS 13,Swift 5。
https://stackoverflow.com/questions/34447238
复制相似问题