Как говорилось в @BCza, лучше всего разбить ваш код на два отдельных контроллера представления, так как они собирают разные данные.Вы можете передать информацию из первого VC во второй, а затем всю информацию из второго в ConfirmationVC.Ваш код будет выглядеть так:
Первый VC
class FirstVC: UIViewController {
@IBOutlet weak var firstName: UITextField!
var firstNameS = ""
@IBOutlet weak var lastName: UITextField!
var lastNameS = ""
@IBOutlet weak var birthday: UITextField!
var birthdayS = ""
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func sendPage1(_ sender: Any) {
self.firstNameS = firstName.text ?? "empty"
self.lastNameS = lastName.text ?? "empty"
self.birthdayS = birthday.text ?? "empty"
performSegue(withIdentifier: "P1", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var vc = segue.destination as! SecondVC // cast to SecondVC to set the saved values below
vc.savedFirstName = self.firstNameS
vc.savedLastName = self.lastNameS
vc.savedBirthday = self.birthdayS
}
}
Второй VC
class SecondVC: UIViewController {
@IBOutlet weak var height: UITextField!
var heightS = ""
//These will be given a value upon segueing from the first view controller to the second
var savedFirstName = ""
var savedLastName = ""
var savedBirthday = ""
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func sendPage2(_ sender: UIButton) {
self.heightS = height.text ?? "empty"
performSegue(withIdentifier: "P2", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var vc = segue.destination as! ConfirmationVC // pass the data from both VC's to ConfirmationVC
vc.confirmFirstNameD = self.savedFirstName
vc.confirmLastNameD = self.savedLastName
vc.confirmBirthdayD = self.savedBirthday
vc.confirmHeightD = self.heightS
}
}