0

I am trying to pass my UiTextfield DATA from one view controller to another view controller programmatically. I am not using storyboard, but doing all the code programmatically.

The code below is what I would like to pass from one view controller to another.

var userPhoneNumberTextField: UITextField = {
    let textField = UITextField()
    textField.backgroundColor = .clear
    textField.text = ""
    textField.font = UIFont(name: "Open Sans", size: 30)
    textField.addTarget(self, action: #selector(confirmationCodeAction), for: .editingChanged)
    return textField
}()
Box House
  • 167
  • 1
  • 1
  • 12

1 Answers1

0

There are several possibilities, depending on your architecture:

1) Create your destination view controller and assign the textField.text to a property of that controller - or hand it over in the init function of the destination view controller.

2) Set the textField.text value in an app state / data object that can be accessed from other classes.

3) Make the text field known to the destination view controller and read the text value in there.

Note that solution 2 and 3 are less modular than solution 1.

TheEye
  • 9,280
  • 2
  • 42
  • 58