There are different ways for passing data between controllers in Objective-C. In this example we are going to use NSNotificationCenter for passing data from one view controller to another view controller. NSNotificationCenter is generally used to broadcast or send message within a program. We post a notification at one place and when the task is done it is shown in the desired place.
Let’s take an example to understand this. In this example we are going to take two ContainerView in the ViewController. In one ContainerView we will take a SegmentControl and on clicking different segments the background color of other ContainerView will change.
To start with, drag two ContainerView in the ViewController in Main.storyboard. You can see two new ViewControllers are also included with the ContainerView. In one of the container drag a SegmentControl. Create two classes and assign them to both ContainerView. Create the IBAction of the SegmentControl.
Include the following lines of code to the action of the UISegmentControl from where we are posting the notification :-