Home>

Click here to get an image and next I tried to display in the view of.
I wanted to display the image acquired bymediaItem.artworkin the first view and also in the view after 3 transitions, but it did not work.

Original first view code

var image: UIImage? // globally
~~~
// Pass the song information to the view controller after selecting the instrument
    override func prepare (for segue: UIStoryboardSegue, sender: Any?) {
        let MimikopiView = MimikopiViewController ()
        print ("give image")
        // print (image) // Artwork is included!
        MimikopiView.ReceiveMusicImage = image
    }


Then there is an image properly

Code after 3 transitions

class MimikopiViewController: UIViewController {
    @IBOutlet weak var MusicImage: UIImageView!
    public var ReceiveMusicImage: UIImage!
    @IBOutlet weak var InstrumentImage: UIImageView!

    override func viewDidLoad () {
        super.viewDidLoad ()
        print (ReceiveMusicImage) // nil here
        if ReceiveMusicImage! = nil {
            MusicImage.image = ReceiveMusicImage
        } else {
            MusicImage.backgroundColor = UIColor.gray
        }
    }
}


It is a situation that can not be received.

  • Answer # 1

    Since there is little information, it seems almost impossible to guess, but I thought that I wanted to write ↓.

    // Segue identifier check
    if segue.identifier == "toEBass" {
    // Get the transition destination ViewCntroller
         let EBassView = segue.destination as! EBass
         EBassView.imagedayo = Photo.image
    }
      

    Now I thought that I would try to display even a gray image, but if I changed the code of "Error here" in the first view to EBass.imagedayo = UIColor.gray, Instance member 'imagedayo' cannot I got an error saying be used on type 'EBass'.

    UIColor.grayis not a gray image. UIColor type, just color information.
    Since UIColor type is different from UIImage type, it cannot be assigned as it is.

    Because EBass is a type, not an instance, it must be assigned to EBassView.imagedayo, not EBass.imagedayo.