Pop & Back Button DataPass (StoryBoardID)


ViewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *outputLabel;
- (IBAction)ActionNext:(id)sender;


ViewController.m
#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()
@end

@implementation ViewController

- (IBAction)ActionNext:(id)sender
{
    SecondViewController *second=[self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    second.delegate=self; // protocol listener
    [self.navigationController pushViewController:second animated:YES];
}
-(void)sendDataToPreviousController: (NSString *)string
{
    NSLog(@"Fired");
    self.outputLabel.text = string;
}


SecondViewController.h
#import <UIKit/UIKit.h>

@protocol sendDataBack <NSObject>
-(void)sendDataToPreviousController: (NSString *)string;

@end

@interface SecondViewController : UIViewController
@property (assign,nonatomic) id delegate;


 SecondViewController.m
#import "SecondViewController.h"

@interface SecondViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *inputTextField;

@end

@implementation SecondViewController

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    [_delegate sendDataToPreviousController:textField.text];
}
Advertisements

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 )

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