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

Bug with CrystalBall App?

In the Programming a Background Image lesson, I had to add the following code to the ViewController.m:

UIImage *image = [UIImage imageNamed:@"background.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view insertSubview:imageView aboveSubview:0];

Unfortunately, unlike everything else in the lesson, it didn't actually load the image. All I got was some white (also, if I am correct, the background image will not resize for the iPhone 5, like if we did if we added it via the storyboard).

2 Answers

I believe your last line of code should be:

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

You want "atIndex" rather than "aboveSubview."

@Geoffrey Thanks! That was pretty lame on my part not to see that :P