0

I'm Beginner in iOS development. In my FirstViewController I have two textFields and I use the UITextFieldDelegate to make these two equal the same content. In my SecondViewController I have another textField and I need to make it have the same content with the textFields from the FirstViewController.

FirstViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    _FirstTextField.delegate = self;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    SecondTextField.text = textField.text;
rmaddy
  • 314,917
  • 42
  • 532
  • 579
restor23
  • 3
  • 1

2 Answers2

0

You can pass the variable to the second View Controller in the Segue.

Passing variables between view controllers

Community
  • 1
  • 1
markreed49
  • 41
  • 7
0

Its simple pass the text of text field in FirstViewController to SecondViewController using string and assign the passed string to the text field of SecondViewController

For passing the string you can have many option

1) Using Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"secondViewSegue"]) {
    SecondViewController *objVC = [segue destinationViewController];
    objVC.strText = textfeld.text;
}

2) Passing data directly while pushing

SecondViewController *objVC = [[SecondViewController alloc] initWithNib:@"SecondViewController" bundle:nil];
objVC.strText = textfield.text;
[self pushViewController:objVC animated:YES];
Milap Kundalia
  • 1,566
  • 1
  • 16
  • 24