Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Denise Sonnemberg
3,150 PointsImage IBOutlet - HELP
Hello everyone!! I am pretty new to this world and I having problem understanding something related to IBOutlets.
I want to create something very similar to the Funfacts app we created here in treehouse but instead of words I want it to be images to change.
I cannot find the right code line to write when declaring the IBOutlet (in this case a image) into the IBAction button.
This is my line of code:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var zombieBtn: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func colorBtn() {
zombieBtn.image
}
}
In the zombieBtn.image i cannot complete it to call the image from zombieBtn
If you could help me I would much appreciated!
Thank you so much
1 Answer
Jason Wayne
11,688 PointsYou are actually in the right direction. You already have an outlet for a uiimageview, and an IBAction for a button to display the image when is clicked (i suppose that is what you are trying to achieve).
But let's take a look at the code you written in the IBAction.
@IBAction func colorBtn() { zombieBtn.image }
By having this code written in the IBAction, you are merely just accessing the zombieBtn's image property, but you are not assigning it any image. To do so, you should have something like, zombieBtn.image = UIImage(named:"theImageName")
That should help solve the problem. =]
Denise Sonnemberg
3,150 PointsDenise Sonnemberg
3,150 PointsThat worked perfectly!!!!
thank you so much Jason :D