
那是因为stackview尝试尽可能多地压缩内容。当您最初添加一个表视图时,我假设它没有内容,所以stackview会将宽度压缩为0,因为它没有内容可显示。您必须执行以下两项 *** 作之一:
在表格中填充数据后,您必须设置tableView的框架。我通过计算每个单元的大小来做到这一点。我知道宽度将和包含stackview的视图一样大。所以最终像是
let estimatedHeight = tableView.numberOfRows(inSection: 0) //You may need to modify as necessarylet width = parentView.frame.size.widthtableView.frame = CGRect(x: 0, y: 0, width: width, height: estimatedHeight)
设置tableView的框架后,stackview应该会自动调整。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)