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

code question?

can anybody see the error with this? UIImage *background = [UIImage imageNamed:@"background"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:@"background"];

3 Answers

Stone Preston
Stone Preston
42,016 Points

yes. UIImageView *imageView = [[UIImageView alloc] initWithImage:@"background"];

initWithImage takes an image object as an argument, you are passing it a string @"background". Hint: you created an image object named background in the first line.

Stone, thanks for getting back to me so quickly. The name of the image is background.png. Is not this argument the name of the image? Thanks again for your help.

Stone Preston
Stone Preston
42,016 Points

initWithImage takes a UIImage object as its argument. but the name of your image (@"background" is not a UIImage, its a string. You cant pass a string to initWithImage, you have to pass an UIImage object. You created an UIImage object earlier though called background. You have to use that object somewhere in the second line.

Makes sense. Thanks again for taking the time to help. Steve