[英]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.