How to change UIImageView as background image on parentViewController using swift

522 views Asked by At

I would like to change my UIImageView I used as a background image on my parentViewController after my childView is loaded

in my viewDidLoad, I have this line, that pretty works :

self.parentViewController?.view.addSubview(myBackgroundImage)

I wish to change it while I got an event on app. But when I try again to change it by using the same line as above it doesn't work.

Anyone have a solution ?

1

There are 1 answers

0
yurikoles On BEST ANSWER

I think it is a bad practice to access the view from another controller. I will suggest you to create separate method for this. Or may be just use IBoutlet for this, for example:

self.parentViewController?.myBackgroundImageView.image = UIImage("your_image")