我正在设计一个页面,其中有一个滚动视图和上面一个表格视图(禁用滚动)。为了实现这一点,我查阅了这个问题的答案 - Make UITableView not scrollable and adjust height to accommodate all cells,但没有成功。
视图层次结构及所提供的约束-
-主视图
-滚动视图
固定到主视图的所有边缘(0,0,0,0),与边距有关的约束
-内容视图
固定到滚动视图(0,0,0,0),宽度等于主视图,高度等于主视图(优先级- 250)
-内容视图中的表格视图
禁用滚动,四周留有50点空白,高度(≥),底部间距50(关系≥)。我使用大于等于号来动态增加高度。
现在当我填充我的表格视图时,我使用以下代码
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
}
所以当我运行我的代码时,它增加了表视图框架但没有拉伸内容大小,这使得滚动视图无法滚动到表视图的末尾,也使我的表视图不遵守自动布局约束。
cellForRowAtIndexPath
中调用tableview.frame.size = tableview.contentSize
。 - aaisataev