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

Why not working? I already initialise with UIImage

// 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 imageName:@"background"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:background]; [self.view insertSubView:imageView atIndex:0];

1 Answer

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Wai,

the question ist "Our Random Quotes app is looking bland and we need to add a background image to it. We started to create a UIImageView, however, the code does not seem to work. Figure out what is wrong and if you need to declare another object to complete this declaration."

So, we've got two tasks to accomplish here:

(1) "Figure out what is wrong..."

- (id)initWithImage:(UIImage *)image likes to have a UIImage and not a NSString, so:

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

and

(2) "...if you need to declare another object to complete this declaration..."

You first need to declare the UIImage, that's used in the UIImageView:

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

So in completion that should be:

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