Search code examples
swiftxibtransfer

Need help transferring multiple strings from one .XIB file to a view controller


My goal is to try and pass multiple names from one input in an XIB view to a view controller file. It's a very simple issue, but I haven't found a solution online.

This is what I'm using to try and transfer the string input currently.

    let nameOne = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
    nameOne.swimmerOneName = swimmerOneTextField.text!

    let nameTwo = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
    nameTwo.swimmerTwoName = swimmerTwoTextField.text!

    let nameThree = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
    nameThree.swimmerThreeName = swimmerThreeTextField.text!

    let nameFour = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
    nameFour.swimmerFourName = swimmerFourTextField.text!

    navigationController?.pushViewController(nameOne, animated: true)
    navigationController?.pushViewController(nameTwo, animated: true)
    navigationController?.pushViewController(nameThree, animated: true)
    navigationController?.pushViewController(nameFour, animated: true)

My issue is that it only transfers one name at a time with an animation each time also. I have tried setting the "animated: true" to false however it still only transfers each name one at a time.

To make it more clear this is what I'm trying to accomplish. This was done using segues and the storyboard, not an XIB: Images 1 and 2

Entering Names (View Controller and Segue) Information Transferred (View Controller and Segue) Entering Information (With XIB) Transferring names (With XIB)

This is what is happening to me when I want to transfer all the names: Images 3 and 4. It cycles through each one and doesn't keep them all at once like in image 2.


Solution

  • you can define a global array of String and transfer your text with this array but better way is using one of pass data methods.