Home>

I want to create a function that when you tap the button, the characters typed in the text field and the displayed image are displayed as they are at the screen transition destination.
I could have a code to display at the transition destination using IBAction just by passing characters by value,
If this is the case, it cannot be passed at the same time.

self.dismiss (animated: true)

I wanted to pass the screen transition, value, and image reference by reference after, so I tried to insert a button action, but it did not. How can I pass the value to the transition destination? I would be grateful if you could answer.

@IBAction func next (_ sender: Any) {
        let viewController = posterViewController.makeInstance (textLabel: textFieldView.text)
                self.present (viewController, animated: true, completion: nil)
                    }
}
    // Processing called after selecting a photo
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    // Processing called after selecting a photo
    func imagePickerController (_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
        // Get the selected photo
        let image = info [.originalImage] as! UIImage
        // Show in view
        imageView.image = image
        // Withdraw the view to select a photo
        self.dismiss (animated: true)
    }
}

Transition destination

class posterViewController: UIViewController {
    @IBOutlet weak var textLabelView: UILabel!
    private var textLabel: String?
        static func makeInstance (textLabel: String?)->PosterViewController {
            let storyboard: UIStoryboard = UIStoryboard (name: "poster", bundle: nil)
            let viewController = storyboard.instantiateViewController (withIdentifier: "posterViewController") as! PosterViewController
            viewController.textLabel = textLabel
            return viewController
        }
        override func viewDidLoad () {
            super.viewDidLoad ()
            textLabelView.text = textLabel
        }
    }

Development environment

swift5 xcode 12.1