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


Crystal ball code challenge background image

Hey guys, So I have been stuck on the code challenge for Programming a Background Image for the Crystal Ball iPhone App. I have been trying to get this right and there are already two discussions on this topic but they don't seem to answer the question. Here's what is required: 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.

This is what I have so far but I don't know how to proceed. It keeps on giving me an error saying “use of undeclared identifier self” but it works in xcode.

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

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

[self.view insertSubview:imageView atIndex:0];

So, let me know if I’m missing something. Thanks.

1 Answer

This is a very common mistake among students it seems. Every other day this question pops up in the forum... :/

Start from scratch, you probably changed the 3rd line beyond repair anyway.

The bug the question asks you to fix is actually in the second line. UIImageView's initWithImage: method, as the signature suggests, takes an image, i.e. UIImage as an argument (You can confirm this by checking the Apple documentation).

What you had there was, i.e. @"background", is just the name of the image as a string. But you need an UIImage instead, where can you find one? Well, you just made one in the line above. Toss the variable name of that image into the method and you should be set.