iosswiftuicontainerviewchildviews

Change child of iOS Container View from child interaction


I have a Container View that contains a view. I want to change this view to another, calling a method of the parent view when the user interacts with an object of this child view.

How can I do this?


Solution

  • let say the container is a class named 'ContainerView' and it has a function called 'changeSubView'
    from the child view you can call it using:

    let containerView = self.superview as! ContainerView
    containerView.changeSubView()