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 trialSteve Nicollerat
5,880 Pointscode question?
can anybody see the error with this?
UIImage *background = [UIImage imageNamed:@"background"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:@"background"];
3 Answers
Stone Preston
42,016 Pointsyes.
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.
Steve Nicollerat
5,880 PointsStone, 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
42,016 PointsinitWithImage 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.
Steve Nicollerat
5,880 PointsMakes sense. Thanks again for taking the time to help. Steve