How to transfer image between view controllers without using segue

I get the error :

Subject 1: EXC_BAD_INSTRUCTION (code = EXC_1386_INVOP, subcode = 0x0)

when trying to transfer an image selected from the photo library to another view controller.

Source ViewController -

@IBAction func myButtonTapped(_ sender: UIButton) 
   {
        let secondVC = storyboard?.instantiateViewController(withIdentifier: "secondVC") as! secondVC
        secondVC.passedVName = VNameTextField.text!
        secondVC.passedCcName = DropTextBox.text!
        secondVC.passedVImage = VImageView.image! 
        navigationController?.pushViewController(secondVC, animated: true)

    }

The purpose of the ViewController is

 class secondVC: UIViewController 
    {
        @IBOutlet weak var DisplayPassedImage: UIImageView!
        @IBOutlet weak var ccNameDisplayLabel: UILabel!
        @IBOutlet weak var VNameDisplayLabel: UILabel!
        var passedVName = ""
        var passedCcName = ""
        var passedVImage = UIImage() 
        override func viewDidLoad() 
            {
            super.viewDidLoad()
            VNameDisplayLabel.text = passedVName
            ccNameDisplayLabel.text = passedCcName
            DisplayPassedImage.image = passedVImage // Error- Thread 1:EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=0x0)
            }
    }

Note. . PassedVName and 'passCcName' data are successfully passed to the target ViewController. if I try to pass 'passVImage', I get an error message.

+4
source share
2 answers

NotificationCenter / viewController. UIImage AppDelegate ( ), .

Ex.
1) firstVC
2) VC , AppDelegate
3) firstVC, .
4) SecondVC
5) AppDelegate ( ).

.

+1

.jpg .png

0

Source: https://habr.com/ru/post/1665116/


All Articles