[英]How to update the contentSize of UIScrollView in a parent controller from a UITableView in Child viewController
我使用以下代码从子viewController更新父控制器的约束,但是这会产生问题:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("in will display row - \(indexPath.row)")
if (UIApplication.visibleNavigationController.visibleViewController is UserPrfileControl){
if (UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).childControllerToUpdate == "userPost"{
(UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).commentViewHeight.constant = 0
(UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).burnedPostsHeight.constant = 0 .
(UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).userProfileViewHeight.constant = self.tableView.contentSize.height
}
}
}
我建议您在viewDidLayoutSubviews中创建此代码,请不要使用这种方式(UIApplication.visibleNavigationController.visibleViewController为!UserPrfileControl),只需为父控制器添加属性即可。
必须尝试self.tableView.reloadData ()
,然后获取tableView contentSize 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.