BackWord data passing in xcode.

step 1. Define a protocol in FirstViewController.h

#import <UIKit/UIKit.h>

@protocol ViewBProtocol

– (void)setData:(NSString *)data;


@interface MSYViewController : UIViewController<ViewBProtocol>


Step 2. in FirstViewController.m

– (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

UIViewController* controller = [segue destinationViewController];

if ([controller isKindOfClass:[MSYQuizView class]])


MSYQuizView* viewCController = (MSYQuizView *)controller;

viewCController.delegate = self;



// where MSYQuizView is second ViewController.

// implement protocol method.

– (void)setData:(NSString *)data{

NSLog(@” data is %@ “,data);


Step 3 . In SecondViewController named MSYQuizView.h

#import <UIKit/UIKit.h>

#import “MSYViewController.h”

@interface MSYQuizView : UIViewController

@property (nonatomic, weak) id<ViewBProtocol> delegate;


Step 4. In MSYQuizView.m  ( SecondViewController).

– (void)sendData:(NSString *)data


NSLog(@”send………… %@”,data);

[self.delegate setData:data];


// Call it AnyWhere you want like this

– (void)viewDidDisappear:(BOOL)animated


[super viewDidDisappear:animated];

[self sendData:@”now success to complete”];




One thought on “BackWord data passing in xcode.

Add yours

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: