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 trialTom Dunwoody
853 PointsI simply cannot understand how to complete this !
I need to pass a UIImage to the instance variable "backgroundImage". But there is no external or internal file or anything. otherwise I will need to pass a string (@"background").
3 Answers
Holger Liesegang
50,595 PointsI 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.
Holger Liesegang
50,595 PointsHi Tom,
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"];
Kind Regards Holger
Tom Dunwoody
853 PointsThis is still bringing up an error =[. It says that UIImageView needs to be initialized a UIIMage object.