简体   繁体   中英

How to change UIImageView as background image on parentViewController using swift

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 ?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM