I want to pass data on Dismiss View controllerB
To View controllerA
and pass two text field value to View controllerA
Below posted code not working for me!
ViewController B
ClassB.h
#import <UIKit/UIKit.h>
@protocol SecondDelegate <NSObject>
-(void) secondViewControllerDismissed:(NSString *)stringForFirst
@end
@interface SecondViewController : UIViewController
{
id myDelegate;
}
@property (nonatomic, assign) id<SecondDelegate> myDelegate;
ClassB.m
@synthesize myDelegate;
//Below Code Into my button Click
if([self.myDelegate respondsToSelector:@selector(secondViewControllerDismissed:)])
{
[self.myDelegate secondViewControllerDismissed:@"THIS IS THE STRING TO SEND!!!"];
}
[self dismissModalViewControllerAnimated:YES];
ViewController
A
ClassA.h
#import "SecondViewController.h"
@interface FirstViewController:UIViewController <SecondDelegate>
ClassA.m
Now when you instantiate secondViewController in firstViewController you should do the following:
// Here I am using below Code
ClassB *BViewController;
[self.storyboard instantiateViewControllerWithIdentifier:@"BViewController"];
[self presentViewController:BViewController animated:YES completion:nil];
- (void)secondViewControllerDismissed:(NSString *)stringForFirst
{
NSString *thisIsTheDesiredString = stringForFirst; //And there you have it
}