BackWord data passing in xcode.


step 1. Define a protocol in FirstViewController.h

#import <UIKit/UIKit.h>

@protocol ViewBProtocol

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

@end

@interface MSYViewController : UIViewController<ViewBProtocol>

@end

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;

@end

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”];

}

Thanks.

Advertisements

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:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: