【发布时间】:2016-03-30 13:42:02
【问题描述】:
我正在设计一个具有滚动视图的页面,其上方是一个表格视图(禁用滚动)。为此,我在这个问题中提到了答案 - 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
}
所以当我运行我的代码时,它会增加 tableview 框架但不会拉伸内容大小,而且它会变得很奇怪,因为我的滚动视图没有滚动到 table view 的末尾,我的 table view 也不服从自动布局约束。
【问题讨论】:
-
我猜你不应该在
cellForRowAtIndexPath中调用tableview.frame.size = tableview.contentSize -
@aaisataev 没错。看看我的回答
-
参考这些链接.. stackoverflow.com/questions/19036228/…> developer.apple.com/library/ios/documentation/UserExperience/…>。希望对您有所帮助... :)
标签: ios swift uitableview uiscrollview autolayout