Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 根据SWIFT中其子表视图的高度调整scrollview的高度_Ios_Uitableview_Swift_Uiscrollview_Autolayout - Fatal编程技术网

Ios 根据SWIFT中其子表视图的高度调整scrollview的高度

Ios 根据SWIFT中其子表视图的高度调整scrollview的高度,ios,uitableview,swift,uiscrollview,autolayout,Ios,Uitableview,Swift,Uiscrollview,Autolayout,我有一个viewController,在scrollview中有一个tableview 我需要以编程方式更新tableview的高度,然后更新scrollview的高度(scrollview的高度取决于tableview的高度) 因此,我在viewController的ViewDidDisplay中编写了以下代码: override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) var

我有一个viewController,在scrollview中有一个tableview

我需要以编程方式更新tableview的高度,然后更新scrollview的高度(scrollview的高度取决于tableview的高度)

因此,我在viewController的ViewDidDisplay中编写了以下代码:

 override func viewDidAppear(animated: Bool) {

    super.viewDidAppear(animated)

    var frame:CGRect = self.tableView.frame
    frame.size.height = tableView.contentSize.height
    self.tableView.frame = frame

    scrollView.contentSize=CGSizeMake(scrollView.frame.size.width, tableView.frame.origin.y + tableView.frame.height)

 }
如果我在控制台中进行检查,则在所有cellForRowAtIndexPath之前调用ViewDidDisplay。在这种情况下,一切都按照我的要求进行

在我的viewController中,我有一个打开modalViewController的按钮。在这个modalViewController中,我在我的tableview中添加了一个新数据(因此,一个新单元格)

当我使用dismissViewControllerAnimated关闭我的modalViewController时,会调用ViewDidAspect,但在所有cellForRowAtIndexPath之后。 我的viewController显示不正确,tableview被裁剪,我无法滚动到tableview的底部。我的代码不起作用


我正在使用Swift和auto layout。

尝试在视图控制器中调用此选项:

automaticallyAdjustsScrollViewInsets = false
如果愿意,也可以在Interface Builder中进行设置

automaticallyAdjustsScrollViewInsets = false