0

I have a container view controller with its own view controller class and some UI components. Some events of this container view controller needs to call the main view controller. I'm not able to find how to do it.

class mainViewController :UIViewController {
      var containerView:UIView!
}


class MyContainerView:UIViewController {
     @IBAction func buttonClick(sender:UIButton){
         // change mainViewController background for example
      }
}
2
  • How about some example code to help us help you? :) Commented Jul 24, 2015 at 12:28
  • Delegate, notification, direct access, ... it depends. How are mainViewController and MyContainerView connected to each other? Commented Jul 24, 2015 at 12:34

2 Answers 2

4

So you are trying to get the parent controller right ?

self.parentViewController
Sign up to request clarification or add additional context in comments.

Comments

2

You should register your main view controller to listen to local notifications broadcast from your container view controller to know when it needs to perform some update function or change the UI.

In your main it would be

NSNotificationCenter.defaultCenter().addObserver(self, selector: "performUpdates:", name: "ContainerViewChangedUpdate", object: nil)

Make sure to unregister in viewWillDisappear.

In your container view controller you would send the notification.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.