0

i have a container in my view with two tableview controllers as childs. enter image description here i have the childs as this properties in class

lazy var photoFeedVC: UserPicsTableViewController = self.makeAndAddVC()
    lazy var postFeedVC: PostFeedVC = self.makeAndAddVC()

the function to make the childs

func makeAndAddVC<T: UIViewController>() -> T {
        let vc = T()
        self.addChildViewController(vc)
        return vc
    }

i want to fix each tableview to its container bottom after i increase the size of the container in viewDidAppear.

photoFeedVC.tableView.snp.makeConstraints({(make) -> Void in
        make.bottom.equalTo(containerView)
    })
    postFeedVC.tableView.snp.makeConstraints({ make -> Void in
        make.bottom.equalTo(self.view)
    })

this is a contrainst tryin to fix to bottom but xcode gave me this error

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors and because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'

here the method to increase the container

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(true)
        print("aparecio la vista")
        containerView.frame.size.height += 150
        self.feed.frame.size.height += 150.0
        self.photoFeedVC.tableView.frame.size.height += 150.0
        self.postFeedVC.tableView.frame.size.height += 150
        self.scrollView.contentSize.height = containerView.height + 10
        self.scrollView.layoutIfNeeded()
    }

1 Answers1

1

The error message in question is saying you're pinning 2 views that aren't in the same hierarchy. You're missing an addSubview() call somewhere (though I can't say exactly where, because there seem to be a lot of child view controllers and I'm not sure what the hierarchy should look like).

You're also doing both frame math and auto layout, which, except in very rare cases, is not what you want. If you want to be using auto layout, you should be modifying constraints to expand a container, not adjusting anything's frame.height.

Connor Neville
  • 7,291
  • 4
  • 28
  • 44
  • i have edit the question to show the view composition and how the childs get added to the view. this all elements are inside a scrollView. the frame increase issue was a request from client to hide upper part when scrolling so the solution was increase the container height, the problem is that both tableviews does not grow up as container does. –  Nov 13 '17 at 14:52