0

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;

}
Assam AlZookery
  • 479
  • 4
  • 15
  • sounds like you want to use the text field as a model. don't do that. don't mix UI and model. – vikingosegundo May 25 '16 at 17:04
  • so what's the best way get one input from the text filed to these two view controllers. @vikingosegundo – Assam AlZookery May 25 '16 at 17:14
  • dont do it. create similar text fields. – vikingosegundo May 25 '16 at 17:19
  • Sorry, but i don't understand by create similar text filed @vikingosegundo – Assam AlZookery May 25 '16 at 17:22
  • Sorry, I fail to see what is not understandable here. Create to fields, make them look similar. – vikingosegundo May 25 '16 at 17:25
  • I don't want to create another text file, i want the user to enter the data once @vikingosegundo – Assam AlZookery May 25 '16 at 17:27
  • than I haven't get the foggiest idea what you want to do. But in the end it just boils down to passing data. – vikingosegundo May 25 '16 at 17:55
  • @vikingosegundo i already changed my question to passing data between view controllers, so I can pass data between these two view controller, in my code it will pass the data by pushing the button and it will take me to viewcontroller2, so don't want to go to the second view controller because I'm using UISwipeGestureRecognizer to navigate between these view controller. how can i do that? Thank you for your help – Assam AlZookery May 25 '16 at 20:02
  • http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers?rq=1 – vikingosegundo May 25 '16 at 20:04
  • are you want to set ViewController2 text field value from first view controller ? – balkaran singh May 26 '16 at 10:29
  • yes that's correct, also i don't want to click the button and it will take me to the second view controller, because i'm using UISwipeGestureRecognizer. Would you please answer this question. i will really appreciate it @balkaransingh – Assam AlZookery May 26 '16 at 12:45
  • so you want to call - (IBAction)button:(id)sender on UISwipeGestureRecognizer ? – balkaran singh May 26 '16 at 12:59
  • so (IBAction)button will be use to pass the data to the second view controller. the UISwipeGestureRecognizer will be use to swipe between view controller 1 and view controller 2 @balkaransingh – Assam AlZookery May 26 '16 at 13:41

0 Answers0