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

Steve B
Steve B
6,257 Points

programming a background image code challenge

Building a simple iPhone app 5:4

http://teamtreehouse.com/library/programming-a-background-image-2

Im having trouble passing this challenge, I've looked at this a thousand times and I cant see whats wrong - Im sure its stupidly obvious!

My code

// The following code is excerpted from 
// the viewDidLoad method of THViewController.m

// Fix the code below 
// Hint: First create an instance of UIImage

UIImage *background = [UIImage imageNamed:@"background"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: background];"
Stone Preston
Stone Preston
42,016 Points

can you post a link to the challenge and what task you are on

4 Answers

Stone Preston
Stone Preston
42,016 Points

currently you have a double quote at the end of your last line. try removing it:

What you currently have:

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

remove the quote:

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

also, the imageView may be a property of your viewController (it most likely is), so you might need to access it using self and access the image property of the imageView like so: (also note that you wouldnt allocate/init it if it was a property):

UIImage *background = [UIImage imageNamed:@"background"];
self.imageView.image = background;
Andrew Pope
Andrew Pope
11,915 Points

The code is right, however you just have a " at the end of the last line which is creating the error! Delete it and it should be fine.

what about the " at the end of the line? ...

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

also for imageNamed: call ...

"On iOS 4 and later, if the file is in PNG format, it is not necessary to specify the .PNG filename extension"

is "background" a png file?

Steve B
Steve B
6,257 Points

Yes, it was quotation mark!

Thanks for your help peeps :-)