This question seems to be very popular here on stack overflow. My question is a little bit different.
I have Two view controllers ViewController1
and ViewController2
I can successfully pass data between these two view controllers by clicking a button that will pass the data and take me to the second view controller. In my application I'm using UISwipeGestureRecognizer to navigate between these view controllers. So I just want to pass the data by clicking the button without going to the second view controller since I'm using UISwipeGestureRecognizer
here's my code
ViewController1.M
#import "ViewController1.h"
#import "ViewController2.h"
@interface ViewController1 ()
@end
@implementation ViewController1
@synthesize textfield;
-(void)viewDidLoad{
[super viewDidLoad];
self.textfield.delegate = self;
}
- (IBAction)button:(id)sender {
ViewController2 *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
vc2.stringfromTextfield1 = self.textfield.text;
[self presentViewController:vc2 animated:YES completion:nil];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
return [textfield resignFirstResponder];
}
ViewController2.M
#import "ViewController2.h"
#import "ViewController1.h"
@interface ViewController2 ()
@end
@implementation ViewController2
-(void)viewDidLoad{
[super viewDidLoad];
self.label.text = self.stringfromTextfield1;
}