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
Stu Cowley
26,287 PointsCreate a Simple iPhone App Code Challenge: Programming a 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 for a couple days but I keep getting an error.
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.
Here is what I I currently have:
// The following code is excerpted from
// the viewDidLoad method of THViewController.m
// Fix the code below
// Hint: First create an instance of UIImage
UIImage *backgroundImage = [[UIImage imageNamed:@"background"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:@"background"];
What do you think Amit Bijlani ?
Any help will be greatly appreciated.
Stu :)
1 Answer
Stone Preston
42,016 Points[[UIImageView alloc] initWithImage:@"background"];
the method initWithImage takes an image as an argument, not a string. See if you can figure it out now. You just created an image in the line above it so it should be easy to fix now
Rashii Henry
16,433 PointsHow will you always know what parameters a method can take?
Stone Preston
42,016 PointsMost of the time the method name will hint at it such as initWithImage. Xcode also shows you when you autocomplete a method. It will have the argument types in grey. You can also check the apple docs
Dastan Aryngazy
Courses Plus Student 1,660 PointsDastan Aryngazy
Courses Plus Student 1,660 Pointsyou should delete after initWithImage, @""; thats all.