我有一个UIViewController,其中有UIScrollView,而在3个 UIContainerViews 中有三个子UIChildViewControllers,每个UIChildViewController都有一个 UITableView 。当我从UIChildViewControllers更新 UIContainerView 的高度(以在父控制器中获取 UIScrollView 的高度)时,将加载Web服务中的所有页面。这是导致所有页面加载的代码:
_ = (UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).commentViewHeight.constant = 0 //make the height of one of non visible viewcontroller's containerView to 0
_ = (UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).burnedPostsHeight.constant = 0
_ = (UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).userProfileViewHeight.constant = self.tableView.contentSize.height
当我从代码分页中删除上述行时可以正常工作,,但是当我使用它们来更新UIContainerView的高度限制时,打开Web服务时,一次从Web服务加载所有页面控制器。这里是 加载新页面的完整方法:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
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
}
}
if pageNumber >= totalPages {
return
}
else
{
if (listData?.count)! == 10*pageNumber{
if (listData?.count)! - 3 == indexPath.row{
if !boolHitApi{
boolHitApi = true
return
}
pageNumber += 1
if pageNumber >= 2{
if (UIApplication.visibleNavigationController.visibleViewController is UserPrfileControl){
_ = (UIApplication.visibleNavigationController.visibleViewController as! UserPrfileControl).userProfileViewHeight.constant = self.tableView.contentSize.height
}}
self.callService()
}
}
}
}