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

iOS Build a Simple iPhone App (iOS7) Designing your App Programming a Background Image

Stuck on UIImage code challenge...

Hello, I have used the following code, but still am having initialization errors on the code challenge check.

UIImage *background = [UIImage imageNamed:@"backgroundImg"];

UIImageView *imageView = [[UIImageView alloc] initWithImage:background];

What am I doing wrong?

2 Answers

Colin Jackson
Colin Jackson
4,829 Points

Here's what worked for me:

UIImage *background = [UIImage imageNamed:@"background"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:background];

Looks like you're using the background image name @"backgroundImg" from the video, and I think the point of the code beginning with UIImageView *imageView = [[UIImageView alloc] initWithImage:@"background"]; is to hint that the programmer was trying to add an image named "background" straight to the UIImageView instead of initializing it with a UIImage first. Hope this helps!

Ah! I bet that is it. I follow along on Xcode, and I bet I got tied up using naming conventions I was getting comfortable with.

I will give this a shot. Thanks!