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

UIImageView is not initialized a UIImage object. Programming a background image. Need help !

Attempting to program a background image.

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

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

Not sure why this isnt working.

2 Answers

I answered the following to your other question a view minutes ago and by now seeing your code I think I've been right with the wrong order of the two declarations :)


I just tested Challenge task 1 of 1 with

// 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];

and it passed without a problem. I'm afraid you tried to declare the 'UIImage *background' after the 'imageView' declaration, and '[[UIImageView alloc] initWithImage:background]' already needs to have the 'background' variable.

ohh so it runs line by line? ... sorry i didnt know how else to fix this as it has been a frustrating issue. I apologize for the duplicated post. So i need to declare background before assigning. It makes sense now. I wasnt sure if it mattered, as long as the variables respected each other with values and declarations.

Yes, the order matters, no problem and keep on learning, Tom Dunwoody - it's getting better every day and don't forget to have some fun while programming :)