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 trialAaron Anderson
2,541 PointsImage won't load
I copied the exact code but when i run the app.... the image wont load. Just the background color of the UIView shows. Help?
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
@IBOutlet weak var playlistView1: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press This Button!", forState: .Normal)
let playlist = Playlist(index: 0)
playlistView1.image = playlist.icon
}
Aaron Anderson
2,541 Pointsyes i used drag and drop to place the images inside the image asset as well as changed it to a vetor
2 Answers
aichi
15,266 PointsHad the same problem and found my solution when I rechecked my code. Go to your Playlist file and check for unnecessary quotation marks given to iconName.
let iconName = playlistDictionary["icon"] as! String!
icon = UIImage(named: iconName)
Jack Hawley
10,665 PointsIt looks like a simple typo. You set the outlet variable as "playlistView1" and it should be "playlistView0" because you are referencing index 0
Try this:
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
@IBOutlet weak var playlistImageView0: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press me!", forState: .Normal)
let playlist = Playlist(index: 0)
playlistImageView0.image = playlist.icon
}
miguelcastro2
Courses Plus Student 6,573 Pointsmiguelcastro2
Courses Plus Student 6,573 PointsHave made sure that you copied the images to the image assets?